joker469 Posted January 15, 2005 Share Posted January 15, 2005 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;} Link to comment Share on other sites More sharing options...
pZy Posted January 17, 2005 Share Posted January 17, 2005 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now