Celsius,Kelvin或Newton to Fahrenheit计算器

时间:2015-03-02 02:59:27

标签: c++

我正在尝试制作一个以摄氏度,开尔文或牛顿为单位的计算器,并以fahreinheit输出度数。作业限制如下。

过去三天我一直在做这项任务,并且在这一点上无法取得任何进展。一个普遍的错误就是这个" cin不是一个过载函数"错误..让我感到困惑!

"必需:

此程序不允许使用do-while循环。

将while循环与switch语句结合使用。请查看有关已启动循环的信息。

在while循环开始之前,您必须使用键盘输入来填充循环。

程序应继续转换温度,直到输入X作为转换类型。

#include <iostream>

using namespace std;

int main()
{
int C;
int N;
int K;
char decision;
char DegreeUnit;
int Temperature;

for(int i = 0; i < 100; i++);// i <100 just for the sake of testing if the loop will work..)

if(tolower(DegreeUnit!='x'))// I want it to lower a capital 'x' so there's no error.. If they put in 'x' program SHOULD terminate..)
{
cout << "What would you like to convert from? And what is the temperatue in that unit?(Press X to exit)" << endl;

cin >> DegreeUnit; // This is where they should put an answer in the following format C 32
cin >> Temperature;

{
    if(DegreeUnit=C) // These if statements are where the maths should occur..

cout << Temperature*(1.8)+32  << endl;
}
{
    if (DegreeUnit=N)

cout <<(Temperature*60)/(11)+32 << endl;
}
{
    if (DegreeUnit=K)

cout << (Temperature-273.15)*1.8 +32 << endl;
}
}// loop here and return to "What would you like to convert from?"

return 0;
}

f有什么我做错了(我可能是哪个)请告诉我..

1 个答案:

答案 0 :(得分:1)

有一个额外的分号,需要将DegreeUnit = C更改为DegreeUnit ==&#39; C&#39; (以及其他DegreeUnit if语句..)

#include <iostream>

using namespace std;

int main()
{
int C;
int N;
int K;
char decision;
char DegreeUnit;
int Temperature;

for(int i = 0; i < 100; i++)// i <100 just for the sake of testing if the loop will work..)
{
if(tolower(DegreeUnit!='x'))// I want it to lower a capital 'x' so there's no error.. If they put in 'x' program SHOULD terminate..)
{
cout << "What would you like to convert from? And what is the temperatue in that unit?(Press X to exit)" << endl;

cin >> DegreeUnit; // This is where they should put an answer in the following format C 32
cin >> Temperature;

{
    if(DegreeUnit=='C') // These if statements are where the maths should occur..

cout << Temperature*(1.8)+32  << endl;
}
{
    if (DegreeUnit=='N')

cout <<(Temperature*60)/(11)+32 << endl;
}
{
    if (DegreeUnit=='K')

cout << (Temperature-273.15)*1.8 +32 << endl;
}
}// loop here and return to "What would you like to convert from?"
}
return 0;
}