C++ - 使用开关的用户输入和输出
C++ - User Input and Output using Switch?
所以我正在尝试创建一个程序,本质上,该程序根据用户的选择要求用户提供各种输入和输出。 我正在使用开关方法以及 cin 来执行此操作。 出于某种原因,它不允许我编译。 任何人都可以提供关于我在这里做错了什么的见解吗? 谢谢!
#include <iostream>
using namespace std;
int main()
{
cout << "Welcome to my countertop store.n" << "Before running this program you will need the depth and
length of the block, which edges are to be finished and
the style, as well as the grade to be used
and the finish.n";
cout << "Please enter the depth of the counter: ";
cin << counterDEPTH;
cout << "Please enter the length of the counter: ";
cin << counterLENGTH;
cout << "Number of long edges to be finished: ";
cin << longEDGES;
cout << "Number of short edges to be finished: ";
cin << shortEDGES;
cout << "Please choose a grade: n";
switch (grade)
{
case Marble:
double cost = 92.99;
case Granite:
double cost = 78.99;
case Quartz:
double cost = 56.99;
case Quartite:
double cost = 39.99;
}
cout << "Selected grade: " & grade;
cout << "Would you like it polished (y/n)? ";
switch (polished)
{
case Yes:
double newcost = cost;
double newcost = (.15 * newcost);
case No:
double newcost = 0.00;
}
cout << "Cost Informationn";
cout << "Stone Cost: " & cost;
cout << "Polishing Cost: " & newcost;
cout << "Edge Cost: " & (longEdges * shortEdges * 4.99);
cout << "Total: " & cost+newcost+(longEdges * shortEdges * 4.99);
return 0;
}
首先,您需要声明几乎所有变量。C 和 C++ 都要求在使用变量之前声明变量,因此到目前为止,您拥有的几乎每个语句都是非法的。
仅从瞥一眼您的计划来看,似乎还有许多其他问题也可能破坏它。在这一点上,如果您尝试自己使用编译器的输出进行调试,它将更加有用,因为我确信到目前为止我发现的所有错误都会被任何编译器发现。
如果仍然遇到问题,则需要提出更具体的问题,最好是与编译器的输出\错误消息一起提出。
cin << counterDEPTH;
将其更改为
cin >> counterDEPTH;
并同样改变他人
这是你的全部代码吗? 您需要声明要将用户输入存储到的变量。 此外,是/否/大理石/花岗岩/石英/四英石也没有在任何地方定义。
#include <iostream>
using namespace std;
int main()
{
cout << "Welcome to my countertop store.n" << "Before running this program you will need the depth and
length of the block, which edges are to be finished and
the style, as well as the grade to be used
and the finish.n";
double counterDEPTH, counterLENGTH, longEDGES, shortEDGES;
cout << "Please enter the depth of the counter: ";
cin >> counterDEPTH;
您的 switch 语句也需要中断。
case Marble:
double cost = 92.99;
break;
case Granite:
double cost = 78.99;
break;
-
将语句更改为
cin
具有>>
,例如cin>>反深度;
-
在
switch
语句的每个case
块的末尾添加break;
。
你已经用<<
写了cin
和cout
。 cin
必须使用>>
.
相关文章:
- C++如何通过用户输入删除列表元素
- 如何使用用户输入在C++中正确填充2D数组
- C++MySQL C api用户输入行
- 如何只允许用户输入正整数
- C++如何计算用户输入的数字中的偶数位数
- 通过for循环使用用户输入填充列表
- 在C++中,我如何接受不同于同一行的用户输入
- 如果用户输入无效,如何使用字符串变量-C++重复输入命令
- 显示基于用户输入的整数的字符
- 根据用户输入用字母填充矢量,并将"开始"和"结束"放在四肢
- 我试图制作一个程序,要求用户输入问题和答案,但程序循环不正确
- 打印时有二叉树问题.用户输入不打印任何内容
- C ++奇怪的数组由用户输入
- 如何允许大写和小写用户输入?
- C++读取用户输入而不按回车键(Mac OS X),与Turbo Pascal中的读取键相同
- 如何存储用户输入的所有数据,然后在他们想要查看所有数据时显示它们
- 如何使用用户输入变量制作二维数组?
- 用户输入字符串的文件附加问题..C++
- 遇到此问题时遇到困难:允许用户输入数组的值并使用 for,而循环也输出输入的最大数字
- 如何使用递归循环我的代码(当用户输入无效输入时,它会再次提示他们)?