您好我的Celsius到Fahrenheit代码有一些错误!第一个错误:
ctoc(float)",引自:
第二个错误:
链接器命令失败,退出代码为1(使用-v查看调用)
#include <iostream>
using namespace std;
float ftoc(float temp);
float ctoc(float temp);
int main() {
bool run = true;
char input;
float temp;
while (run == true) {
cout<<"Enter F for Fahr to Celsius or C for Celsius to Fahr or E to exit.\n";
cin>>input;
if(input == 'e'){
run = false;
} else if(input=='f'){
cout<<"Enter the tempeature in Fahr.\n";
cin>>temp;
cout<<"The temperature in Celsius is "<<ftoc(temp)<<".\n\n\n";
} else if(input == 'c'){
cout<<"The temperature in Fahr is "<<ctoc(temp)<<".\n\n\n";
} else {
cout<<"The character you enteed wasnt valid. Please try again.\n\n\n";
}
}
return 0;
}
float ftoc(float temp){
return (temp-32)/1.8;
}
float ctof(float temp){
return (temp*1.8)+32;
}
答案 0 :(得分:-1)
您正在请求输入单个字符,这对于C ++中的switch语句来说不会有问题。在main上面添加两个函数,并将ctoc更改为ctof。
所以代码看起来像那样:
#include <iostream>
using namespace std;
float ftoc(float temp){
return (temp-32)/1.8;
}
float ctof(float temp){
return (temp*1.8)+32;
}
int main() {
bool run = true;
char input;
float temp;
while (run == true) {
cout<<"Enter F for Fahr to Celsius or C for Celsius to Fahr or E to exit.\n";
cin>>input;
/*
switch statement
*/
}
return 0;
}