C ++程序清除屏幕

时间:2015-10-16 17:57:40

标签: c++ function switch-statement

#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(){

}

如果未激活switch语句,我似乎无法弄清楚如何清除屏幕并返回main()。我已经想出如何返回主菜单,但菜单仍然存在。任何帮助将非常感谢我刚刚开始,需要我能得到的所有建议。代码的其他部分似乎运行良好,但如果我有人能看到我正在做的事情的问题,也将非常感激。我也在Mac上使用Xcode。

1 个答案:

答案 0 :(得分:0)

使用while循环显示菜单,直到选中quit并在切换案例中抛出一些中断。

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;
    }
}

请参阅here清除屏幕。