While loop problem.

can someone help me with this problem. Do i need a while loop within a while loop? in the pressure.d2 there is one number greater than 100.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  Put the c// Program Pressure prints appropriate messages based
// on a pressure reading read from a file.  Processing
// continues until the plant is evacuated because of
// a pressure reading over 100. 

#include <iostream>
#include <fstream>
using namespace std;

int main ()
{
  int  pressure;
  ifstream  data;
  data.open("pressure.d2");
                                          
  /* LOOP TO BE FILLED IN */

    data  >> pressure;                                        
                                                            
    /* FILL IN Code to print the message */

    returm 0;
}
Do you want to read the data until until it encounters a pressure greater than 100 ?

Something like this ?
1
2
3
4
5
6
while ( data >> pressure ) {
    if ( pressure > 100 )
        break;
    else
        cout << "The pressure is " << pressure << endl;
}

Topic archived. No new replies allowed.