Thread: C++ Help
View Single Post
Old 06-29-2009, 09:05 PM   #23 (permalink)
Baez
Baez's Avatar
 


Join Date: Sep 2005

Location: Toronto, Canada

Posts: 5,598

Baez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of light

Default Re: C++ Help

Sorry man forgot about something I had to do! Here it is:

Code:
#include <iostream>
using namespace std;

int main()
{
	char answer[5];
	
	while(strcmp("exit", answer))
	{

		cout << "Do you like sushi? Type yes or no (or exit to quit): ";
		cin >> answer;

		if(!strcmp("yes", answer))
		{ 
		cout << "\nWow, you like sushi!\n\n";
		}
		else if(!strcmp("no", answer))
		{
		cout << "\nGood, sushi's gross!\n\n";
		}
		else if(!strcmp("exit", answer))
		{
		cout << "\nExiting...\n\n";
		}
		else
		{
			cout << "\nWell if you can't even type yes or no..."
			        << "\nhow do you expect me to trust your opinion?\n"
			        << endl;
		}
	}

             return 0;
}
I'm not sure if you've learned about while statements but they are extremely useful. It basically tells a portion of the program to keep looping until a certain case is reached. In this case it's if the user types "exit".
__________________



Bacon is like fried sex. -Trotter

Last edited by Baez; 06-29-2009 at 09:09 PM.
Baez is offline