• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

TO: C++

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'

 
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;
}

 
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 😉
 
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🙁
 
#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;
}
 
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;
 
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;
}

 
Originally posted by: WobbleWobble
cin a char and do a case statement for y, Y, n, N 😉

ellaborate😛


<---proprieter of "Moron Mountain"

I tried decalring a char and it didn't work..that was like an hour agao🙂
 
Originally posted by: Goosemaster
ellaborate😛


<---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>
 
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 😛)

#include <conio.h>
...
char m;
m = getch();
 
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 😛)

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

thanks

this proggy..she is going to be a bute😀
 
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 😛)

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

thanks

this proggy..she is going to be a bute😀

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