Solved

# Looping ???? Repost

Posted on 2004-09-18
Medium Priority
277 Views
Okay, I believe I got the "exit criteria" to work.  However, I am not have any sucess with the loop. What do I need to do? Please comment . Thanks much
#include <iostream>

using namespace std;
class temp
{
private:

static float num1;
static float num2;
double numF;
double numC;

public:

float inputTempF();
void calcTemp();
void displayTempC();
};

float temp::num1 = .555555;
float temp::num2 = 32;

main()
{

temp theTemp;

theTemp.inputTempF();
theTemp.calcTemp();
theTemp.displayTempC();
system("Pause");

}

float temp::inputTempF()
{
cout << "Please enter a temp in F: ";
cin >> numF;
if(numF == 9999)
{
cout<< "Good-Bye"<<endl;
system("Pause");
exit(0);
}
cout << endl;
return numF;

}

void temp::calcTemp()
{
numC =(num1*(numF-num2));
}

void temp::displayTempC()
{
cout << "The C temp is "<< numC ;
cout << endl;

}
0
Question by:bananaamy
• 2

LVL 19

Accepted Solution

drichards earned 2000 total points
ID: 12093411
You don't have a loop in your program.  It just asks for an input, converts to deg C and exits after a pause.

Try replacing your 'main' function with this:
-----------------------------
main()
{

temp theTemp;

while ( true )
{
theTemp.inputTempF();
theTemp.calcTemp();
theTemp.displayTempC();
system("Pause");
}
}
-------------------------------

Is that more like what you were after?  Also, main really should be:

int main( int, char**)
{

return 0;
}
0

LVL 19

Expert Comment

ID: 12093419
Also, you get more aesthetically pleasing results if you use:

float temp::num1 = 5.0/9.0;

Then if you enter 212 the result is 100 instead of 99.999
0

## Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.