Advertisements

While Loops

#include <iostream> //Programmer Rant4u
#include <string> //using while loops
#include <cmath> // 3/12/12
using namespace std;
int main()
{
char ch1, ch2;
int number1, num1;
string word;
bool word2 = false;

cout <<“1.) Would you like to play with bools?”<<endl; //starting menu
cout <<“2.) Would you like to exit the program?”<<endl;

cout <<“Enter a number from the menu to select”; //asking for a selection
cout <<endl;
cout <<endl;
cin >> number1;

switch (number1) // switches number one with a number
{
case ‘1’: number1 = 1;
break;
case ‘2’: number1 = 2;
break;

}

if (number1 == 1) // executes when 1 is selected
{
cout << “You have selected to play with bools, here we go!!”<<endl; //output if 1 is slected
cout <<“Is it true that you can watch the world turn? (y or N)”<<endl;
cin >> ch2;

while(ch2 == ‘y’) //enter the loop when the user beilieves you can watch teh earth turn
{

cout <<“I believe that is incorrect try again (y or n)”<<endl; // give them another shot
cin >> ch2;
ch2 = toupper(ch2);
switch (ch2) //swith char to upper n lower
{
case ‘Y’: ch2 = ‘y’; //actually this does nothing
break;
case ‘N’: ch2 = ‘n’;
break;

}
if (ch2 == ‘n’) //if they admit they cant watch the earth turn
{
cout << “your right congrats”<<endl; //ends the program when they admit they cant
system (“pause”);
return 0;
}
else
{
cout << “try again please”<<endl; //asking them to try again
cin >> ch2;
}

}

}

if(number1 == 2) //selection from the menu
{
cout <<” you can exit the program after you enter the name of this class”<<endl; //output
cin >> word;

while (word != “c++”) //if tehy enter the name of the class correctly
{

if(word == “c++”)
{
cout << “you may now exit, cause your soo samrt”; //they can exit if they get it right
}
else
{
cout <<“that is not the name of the class…”<<endl; // asking for the right answer
cout <<“lets try it again:)”<<endl;
cout <<” you can exit the program after you enter the name of this class”<<endl;
cin >> word;
}
}

}

system (“pause”);
return 0; //end of program
}

Advertisements

About Rant4u

A Revolution in Social Networking

Posted on March 13, 2012, in #c++ loops, #C++ programming, #rant-4u. Bookmark the permalink. Leave a comment.

Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: