0
#include <iostream>
#include <iomanip>

using namespace std;

void far_cels();
void cels_far();
void quit();
void answerF(double);
void answerC(double);
double getTemp();



int main()
{
cout << "--MENU--\n" << "PLease make a selection\n"
     << "1: Farenheit to Celsius conversion\n"
     << "2: Celsius to Farenheit conversion\n"
     << "3: Quit Program\n"
     << "MAKE SELECTION : ";

int num = 0;
cin >> num;
switch (num) {
    case 1:far_cels();
    case 2:cels_far();
    case 3: quit(); 
    default: return main();
}

}



double getTemp()
{
    double temp;
    cout << "Enter the tempature you want to convert\n";
    cin >> temp;
    return temp;
}


void far_cels()
{
double farenheit;
double celsius;
farenheit = getTemp();
celsius = farenheit - 32 / 1.8;
answerC(celsius);

}
void cels_far()
{
double farenheit;
double celsius;
celsius = getTemp();
farenheit = celsius * 1.8 + 32;
answerF(farenheit);

}
void answerF(double farenheit)
{
cout << "The Tempature is: " << endl;
cout << setprecision (4);
cout << farenheit <<" degrees farenheit " << endl;

}
void answerC(double celsius)
{
cout << "Your temperature is: " << endl;
cout << setprecision (4);
cout << celsius <<" degrees celsius " << endl;

}
void quit(){

}

I can not seem to figure out how to clear the screen and return main() if the switch statement is not activated. I have figured out how to return to main but the menu is still there. Any help would be greatly appreciated I am just starting out and need all the advice I can get. The other parts of the code seem to work well but if I anyone can see problems in what I am doing that would also be greatly appreciated. I am also using Xcode on a mac.

  • 2
    1: you need some `break`s in your `switch` block. 2: probably don't call `main` recursively. 3: which line do you *think* is supposed to "clear screen"? – MooseBoys Oct 16 '15 at 18:04
  • I wanted to clear the screen if a menu selection was not made. But I have just decided to use a function that couts multiple new lines. – chris101010 Oct 17 '15 at 15:07

1 Answers1

0

use while loop for displaying your menu until quit is selected and throw some breaks into switch cases.

while(true){
    cout << "--MENU--\n" << "PLease make a selection\n"
    << "1: Farenheit to Celsius conversion\n"
    << "2: Celsius to Farenheit conversion\n"
    << "3: Quit Program\n"
    << "MAKE SELECTION : ";

    int num = 0;
    cin >> num;
    switch (num) {
        case 1:far_cels();break; 
        case 2:cels_far();break;
        case 3: quit();
        default: return 0;
    }
}

refer here for clearing screen.

Community
  • 1
  • 1
vishal
  • 2,258
  • 1
  • 18
  • 27