Solved

Looping ???? Repost

Posted on 2004-09-18
2
263 Views
Last Modified: 2010-04-01
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
Comment
Question by:bananaamy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 19

Accepted Solution

by:
drichards earned 500 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**)
{
  // your code here...

  return 0;
}
0
 
LVL 19

Expert Comment

by:drichards
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question