January 15, 200521 yr hi can you guys help me with my c++ im kinda newbie i dontknow why my program wont let me type in a response like yes and do what i want it to do and no so if you guys could fix it up for me please i would very much apprecieate it thanks heres the code/*My program about something just havent figured it out yet*/#include <iostream>#include <stdio.h>using namespace std;char c;main() {cout << " Type in yes or no: \n";repeat: cin >> c; if ( c = 'yes' ) { cout << " Good Job!! !! "; } if( c = 'no' ) { goto end; } else cout << " Sorry That is not a correct response : \n"; goto repeat;end: return 0;}
January 17, 200521 yr Wow, THIS really is code i will remember a long time There are so many mistakes, i don´t know where to start, so i won´t start ...label, goto, void main()...Ok, so here comes a working one:#include <iostream>#include <string>using namespace std;int main(){ string strInput; bool bValidInput = false; cout << "Type in yes or no:" << endl; while (!bValidInput) { cin >> strInput; if ( strInput == "yes" ) { cout << "You typed \"yes\"" << endl; bValidInput = true; } else if( strInput == "no" ) { cout << "You typed \"no\"" << endl; bValidInput = true; } else { cout << "No correct input" << endl; } } return 0;}I know, it´s also not the best looking, but it think it´s ok for learning purposes.The biggest advantage is, that it uses the "string" class to store and compare strings.If you have more explicit questions, just ask.so far.
Create an account or sign in to comment