Kamis, 27 Maret 2014

Ebook Chapter 5 Problem Solving and Program Design in C

  • 5.6 Figure 5.10 Sentinel-Controlled while Loop
#include <cstdlib>
#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

 

Anita © 2010

Blogger Templates by Splashy Templates