我正在使用我的菜单驱动程序来调用函数。编译器告诉我,我的所有cin,cout和我的函数中的endl语句都是错误的当我尝试执行该程序时。关于如何解决这个问题的任何建议?
修改
它给我的错误表明cout,cin和endl都是未声明的标识符。
#include <iostream>
#include <cmath>
using namespace std;
double ic(double inches, double centimeters)
{
cout << "Enter inches" << endl;
cin >> inches;
centimeters = 2.54*inches;
return centimeters;
}
double ci(double centimeters, double inches)
{
cout << "Enter centimeters" << endl;
cin >> centimeters;
inches = centimeters * .3937007874;
return inches;
}
double fim(int feet, double inches, double meters)
{
cout << "Enter feet " << endl;
cin >> feet;
cout << "Enter inches " << endl;
cin >> inches;
inches = feet * 12 + inches;
meters = inches / 39.370;
return meters;
}
double mfi(double meters, int feet, double inches)
{
feet = 0;
inches = 0;
meters = 0;
cout << "Enter meters. " << endl;
cin >> meters;
inches = meters * 39.37;
while (inches > 12)
{
if (inches > 12)
inches = inches - 12;
feet++;
}
return feet, inches;
}
int main()
{
double inches, meters, centimeters;
int exit = 1, feet;
char choice;
while (exit == 1)
{
cout << "Basic Conversion Calculator" << endl
<< "a. Inches to centimeters" << endl
<< "b. Centimeters to inches" << endl
<< "c. Feet and inches to meters" << endl
<< "d. Meters to feet and inches" << endl
<< "e. Quit" << endl;
cout << "Insert Option:";
cin >> choice;
switch (choice)
{
case 'a': case 'A':
centimeters = ic(inches, centimeters);
cout << centimeters << "cm" << endl;
break;
case 'b': case 'B':
inches = ci(centimeters, inches);
cout << inches << "in" << endl;
break;
case 'c': case 'C':
meters = fim(feet, inches, meters);
cout << meters << "m" << endl << endl;
break;
case 'd': case 'D':
feet = mfi(meters, feet, inches);
inches = mfi(meters, feet, inches);
cout << feet << " ft and " << inches << "in" << endl;
break;
case 'e': case 'E':
exit = 0;
break;
default:
cout << "Input Error!" << endl;
}
}
return 0;
}
答案 0 :(得分:-1)
我将你的代码复制到我的视觉工作室,它的工作完美! :)
我确实有另一个问题,我为了使其工作而修复了这个问题: 变量“双英寸,米,厘米;英尺;”在给它们任何值之前在开关中使用。您可以将它们全部设为0,因为您无论如何都要在函数中从用户那里获取新值。
希望我有所帮助! 祝你好运!