我的导师要求我在杯子里制作一个测量工具,其产量等于加仑,夸脱,品脱等。
该程序用于存储将用于计算转换的常数。 输出将列出一个表。
我难以从哪里开始。有什么建议吗?
好吧,所以我找到了一个转换器,但是我把新线放在错误的位置并且似乎无法弄清楚它在哪里。
int main(int argc, char** argv) {
float cups, gallons, quarts, pints, tablespoons, teaspoons;
std:: cout << "Please input the value in cups";
std:: cin >> cups;
gallons = cups * .0625;
quarts = cups * .25;
pints = cups * .5;
tablespoons = cups * 16;
teaspoons = cups * 48;
std:: cout << "The number of gallons is ";
std:: cout<<gallons"\n";
std:: cout << "The number of quarts is ";
std:: cout<<quarts"\n";
std:: cout << "The number of pints is ";
std:: cout<<pints "\n";
std:: cout << "The number of tablespoons is ";
std:: cout<<tablespoons "\n";
std:: cout << "The number of teaspoons is ";
std:: cout<<teaspoons"\n";
return 0;
}
这就是我所拥有的,并且没有我的\ n添加会导致语法错误。
好的,所以我想出来了,这是我的最终产品,运行顺畅,看起来很棒。谢谢大家的帮助!
int main(int argc, char** argv) {
float cups, gallons, quarts, pints, tablespoons, teaspoons;
std:: cout << "Please input the value in cups to be converted";
std:: cin >> cups;
gallons = cups * .0625;
quarts = cups * .25;
pints = cups * .5;
tablespoons = cups * 16;
teaspoons = cups * 48;
std:: cout << "That many cups is equal to ";
cout<<"\n";
std:: cout << "Gallons ";
std:: cout<<gallons;
cout<<"\n";
std:: cout << "Quarts ";
std:: cout<<quarts;
cout<<"\n";
std:: cout << "Pints ";
std:: cout<<pints;
cout<<"\n";
std:: cout << "Tablespoons ";
std:: cout<<tablespoons;
cout<<"\n";
std:: cout << "Teaspoons ";
std:: cout<<teaspoons;
return 0;
}
答案 0 :(得分:1)
从HelloWorld开始。
当效果完美时,您可以将输入和转换+输出作为两个独立目标。
对于输入,编写一个将从用户那里拿走一些杯子的功能。
对于转换+输出,编写一个将杯子转换为加仑并打印结果的函数。当它完美地工作时,添加夸脱代码,然后是品脱等等。将转化因子实施为const
变量。
当这两个函数完美地工作时,将它们连接在一起,测试结果并完成。