- 5.6 Figure 5.10 Sentinel-Controlled while Loop
#include <iostream>
#define sentinel -99
using namespace std;
int main(int argc, char *argv[])
{
int sum=0, score;
cout<<"Enter first score(or "<< sentinel<<" to quit)> ";
cin>>score;
while (score != sentinel) {
sum += score;
cout<<"Enter next score ("<<sentinel<<"to quit)> ";
cin>>score;
}
cout<<"Sum of exam scores is "<<sum<<endl;
system("PAUSE");
return EXIT_SUCCESS;
Compile :
0 komentar:
Posting Komentar