English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

#include

using namespace std;

int main()
{
int pH;
cout<<"please tpye the pH to the nearest whole number: ";
cin>> pH;
cin.ignore();
if ( pH < 7 ) {
cout<<"This pH level is acidic \n";
}
if ( pH > 7 ) {
cout<<"This pH level is basic \n";
}
if ( pH == 7 ) {
cout<<"The pH is neutral \n";
}
if ( pH < 0 ) {
cout<<"Please reenter a pH level between 0 and 14 \n";
}
if ( pH > 14 ) {
cout<<"Please reenter a pH level between 0 and 14 \n";
}
cin.get();
}
--- How do you insert the loop here to continually repeat the above when a user hits enter? Thanks for any help.

2006-12-04 08:47:19 · 4 answers · asked by dude605 3 in Computers & Internet Programming & Design

4 answers

wouldn't you just surround it with a do...while block?

For example,

do {
cout << "Please enter...



} while (pH !='Q');

2006-12-04 08:58:57 · answer #1 · answered by BigRez 6 · 0 0

int main()
{
int pH;
while( 1 ) {
cout<<"please tpye the pH to the nearest whole number: ";
cin>> pH;
cin.ignore();

if ( pH < 0 ) {
cout<<"Please reenter a pH level between 0 and 14 \n";
} else if ( pH > 14 ) {
cout<<"Please reenter a pH level between 0 and 14 \n";
} else if ( pH < 7 ) {
cout<<"This pH level is acidic \n";
} else if ( pH > 7 ) {
cout<<"This pH level is basic \n";
} else if ( pH == 7 ) {
cout<<"The pH is neutral \n";
}
}
}

2006-12-04 08:59:01 · answer #2 · answered by WickedSmaht 3 · 1 0

Why would you want to enter an infinite loop. This is a dangerous memory and cpu hog if not done carefully. You should always have an exit point or at least a sleep point so you don't chew the cpu up.

/*Very bad PsuedoCode
Yourloop
Do Something
Sleep for 20 seconds
Pick an exit situation here...never CONTINUOUSLY loop, you want to exit sometime in the future
Loop

2006-12-04 14:04:31 · answer #3 · answered by Jeffrey F 6 · 1 0

complete = 0; for(int i=0;i<3;i++){ std::cin>>volume; complete += volume; } OR complete = 0; std::cin>>volume; complete += volume; std::cin>>volume; complete += volume; std::cin>>volume; complete += volume; observe that std:: isn't required in case you have "employing namespace std;" on your code. In the two case the iostream library is needed.

2016-10-14 00:18:48 · answer #4 · answered by ? 4 · 0 0

fedest.com, questions and answers