Goosemaster

Lifer
Apr 10, 2001
48,775
3
81
stupid question


I want someone to input yes or no to a question and proceed. I simply cannot pull it off? lil help?


THIS WORKS:
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
int celsius;
int fahrenheit;
int m;
int n;

cout << "WELCOME TO THE ULTRACONVERTOR 3000, YOUR SOURCE FOR TEMPERATURE CONVERSION" << endl;
cout << "FUFILLING ALL YOUR TEMPERATRUE NEED SINCE 1955" << endl;
cout << " WOULD YOU LIKE ME TO CONVERT TEMPERATURES TODAY?" << endl;
cout << " Press 1 to continue or 0 not to" << endl;
cin >> m;

if (m == 1)

cout << "great, let's get started!" << endl;


else

cout << " too bad." << endl;

system ("PAUSE");

}


however, I would like to make the input a 'yes' or a 'no'

 

Cooler

Diamond Member
Mar 31, 2005
3,835
0
0
int Java =0;
int * omgNoPointers =&Java;

int ArrayWillNotComplie[10];

struct SystaxError{
int MorErrors ;

SystaxError(){
MorErrors++;
cout<<"ERROR varable MorErrors may not have been itilized"<<endl;
}

};


#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{

string st;
cout << " TYPE YES TO CONTINUE OR NO NOT TO" << endl;
cin >> st;

if (st == "YES")
cout << "great, let's get started!" << endl;


system("PAUSE");
return 0;
}

 

EvilYoda

Lifer
Apr 1, 2001
21,198
9
81
Well 'm' could be just a string, but depending on how detailed you want to get, you'll have to deal with error handling...you could type "YES" or "yes" or "Yes"...

Have fun ;)
 

Goosemaster

Lifer
Apr 10, 2001
48,775
3
81
Originally posted by: EvilYoda
Well 'm' could be just a string, but depending on how detailed you want to get, you'll have to deal with error handling...you could type "YES" or "yes" or "Yes"...

Have fun ;)

I have tried a string, but no dice..I get an error that YES is undeclared


I want to use the SWITCH method to write out all those possible inputs:(
 

Cooler

Diamond Member
Mar 31, 2005
3,835
0
0
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{

string st;
cout << " TYPE YES TO CONTINUE OR NO NOT TO" << endl;
cin >> st;

if (st == "YES")
cout << "great, let's get started!" << endl;


system("PAUSE");
return 0;
}
 

Goosemaster

Lifer
Apr 10, 2001
48,775
3
81
This is what I have now, but it doesn't work:(

cout << " WOULD YOU LIKE ME TO CONVERT TEMPERATURES TODAY?" << endl;

string st;
cout << " TYPE YES TO CONTINUE OR NO NOT TO" << endl;
cin >> st;

switch ( st )
{
case YES:
cout << "great, let's get started!" << endl;
break;
case YEs:
cout << "great, let's get started!" << endl;
break
case YeS:
cout << "great, let's get started!" << endl;
break;
case Yes:
cout << "great, let's get started!" << endl;
break;
case yES:
cout << "great, let's get started!" << endl;
break;
case yEs:
cout << "great, let's get started!" << endl;
break;
case yeS:
cout << "great, let's get started!" << endl;
break;
}
else

cout << " too bad." << endl;
 

Cooler

Diamond Member
Mar 31, 2005
3,835
0
0
Originally posted by: Goosemaster
This is what I have now, but it doesn't work:(

cout << " WOULD YOU LIKE ME TO CONVERT TEMPERATURES TODAY?" << endl;

string st;
cout << " TYPE YES TO CONTINUE OR NO NOT TO" << endl;
cin >> st;

switch ( st )
{
case "YES":
cout << "great, let's get started!" << endl;
case "YEs":
cout << "great, let's get started!" << endl;
case "YeS":
cout << "great, let's get started!" << endl;
case "Yes":
cout << "great, let's get started!" << endl;
case "yES":
cout << "great, let's get started!" << endl;
case "yEs":
cout << "great, let's get started!" << endl;
case ''yeS":
cout << "great, let's get started!" << endl;
}

 

Goosemaster

Lifer
Apr 10, 2001
48,775
3
81
Originally posted by: WobbleWobble
cin a char and do a case statement for y, Y, n, N ;)

ellaborate:p


<---proprieter of "Moron Mountain"

I tried decalring a char and it didn't work..that was like an hour agao:)
 

WobbleWobble

Diamond Member
Jun 29, 2001
4,867
1
0
Originally posted by: Goosemaster
ellaborate:p


<---proprieter of "Moron Mountain"

I tried decalring a char and it didn't work..that was like an hour agao:)

You could also use m = getch() which part of the <conio.h>
 

WobbleWobble

Diamond Member
Jun 29, 2001
4,867
1
0
Originally posted by: Goosemaster
I am not familar with getch:(

<--nooB

I'm assuming you're starting a basic programming class. Just stick with cin or else your teacher might question the usage of getch() (like you're getting help from external sources :p)

#include <conio.h>
...
char m;
m = getch();
 

Goosemaster

Lifer
Apr 10, 2001
48,775
3
81
Originally posted by: WobbleWobble
Originally posted by: Goosemaster
I am not familar with getch:(

<--nooB

I'm assuming you're starting a basic programming class. Just stick with cin or else your teacher might question the usage of getch() (like you're getting help from external sources :p)

#include <conio.h>
...
char m;
m = getch();

thanks

this proggy..she is going to be a bute:D
 

WobbleWobble

Diamond Member
Jun 29, 2001
4,867
1
0
Originally posted by: Goosemaster
Originally posted by: WobbleWobble
Originally posted by: Goosemaster
I am not familar with getch:(

<--nooB

I'm assuming you're starting a basic programming class. Just stick with cin or else your teacher might question the usage of getch() (like you're getting help from external sources :p)

#include <conio.h>
...
char m;
m = getch();

thanks

this proggy..she is going to be a bute:D

getch() works differently in Visual C++, if I remember correctly