【发布时间】:2014-02-26 18:38:08
【问题描述】:
我正在编写一个简单的 c++ 测量程序,它要求用户输入以选择他们想从哪个单位测量单位和单位?但我不知道结构是否正确(我的 C++ 真的很烂)。这是我的代码:
#include <iostream>
using namespace std;
int main()
{
int storeFROM, storeTO;
char mm, cm, m, kk;
cout << "Enter the initial unit (mm, cm, m, or km): ";
cin >> storeFROM;
cout << endl;
if ((storeFROM != 'mm') || storeFROM != 'cm' || storeFROM != 'm' || storeFROM != 'km') {
cout << "--> Sorry unit to convert FROM is invalid" << endl;
}
else if ((storeFROM == 'mm') || storeFROM == 'cm' || storeFROM == 'm' || storeFROM == 'km')
{
cout << "Enter the initial unit(mm, cm, m, or kk) :";
cin >> storeTO;
}
// Calculate the selected units
system("pause");
}
我希望有人可以帮助我询问用户输入以询问他们想要哪个单元,这正是它应该显示的方式:
【问题讨论】:
-
问题中缺少最后一句的某些部分。
-
是的,我没有添加度量计算,因为我可能知道该怎么做,它只是设置了如何提问的结构,是我真正不擅长的部分:(
-
首先将用户输入存储在正确的数据类型中。现在您正尝试将
chars 和stringss 存储在ints 中,然后再将它们与chars 和strings 进行比较。你也不能使用==比较字符串
标签: c++