• 0

GD Help with C++ program


Question

ok Here is the program:

Program promts for and reads an interger value and prints a warning message based on value:

<0 "Error in input"

>=0, <50 'Pressure in the normal range"

>=50, <100 'Pressure on high side"

>=100 "Evacuate"

*************************************

here is my program so far

#include <iostream>

#include <fstream>

using namespace std;

int main ()

{

int pressure;

ifstream data;

bool notNegative = true;

data.open("Shell3.D1");

while(notNegative)

{

data >> pressure;

if (pressure <0)

{

notNegative=false;

cout<< "Error in output"<<endl;

}

if (pressure >= 0 && pressure < 50)

cout << "Pressure in the normal range" <<endl;

if(pressure >=50 && pressure < 100)

cout << "Pressure on High Side"<<endl;

if (pressure >=100)

cout << "Evacuate plant!!!"<<endl;

}

return 0;

}

******************************************

shell3.d1 file looks like this:

-3

6

49

50

51

99

1

55

100

*****************************************

now when I execute its reads first number and its stops (says Error lalal ( -3) :angry: :angry:

what I have to do to force this program to check all number and not only 1st one and display on the screen. Please explain I need to know this. Thank u

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0
ok Here is the program:

Program promts for and reads an interger value and prints a warning message based on value:

<0  "Error in input"

>=0, <50    'Pressure in the normal range"

>=50, <100  'Pressure on high side"

>=100          "Evacuate"

*************************************

here is my program so far

#include <iostream>

#include <fstream>

using namespace std;

int main ()

{

    int  pressure;

    ifstream  data;

    bool notNegative = true;

    data.open("Shell3.D1");

    while(notNegative)

{

  data  >> pressure;

  if (pressure <0)

  {

  notNegative=false;

  cout<< "Error in output"<<endl;

  }

  if (pressure >= 0 && pressure < 50)

  cout << "Pressure in the normal range" <<endl;

  if(pressure >=50 && pressure < 100)

  cout << "Pressure on High Side"<<endl;

  if (pressure >=100)

  cout << "Evacuate plant!!!"<<endl;

}

    return 0;

}

******************************************

shell3.d1 file looks like this:

-3

6

49

50

51

99

1

55

100

*****************************************

now when I execute its reads first number and its stops  (says Error lalal ( -3) :angry:  :angry:

what I have to do to force this program to check all number and not only 1st one and display on the screen. Please explain I need to know this. Thank u

584830027[/snapback]

Your while-loop is testing for notnegative. Your first element is negative and sets notNegative to false which exits your loop.

You should do you while loop like so:

while( data &gt;&gt; pressure )

Then test for negativity.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.