所以我试图创建一个程序,它本质上要求用户根据用户的选择进行各种输入和输出。我这样做是使用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 Information\n";
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;
}
答案 0 :(得分:1)
首先,您需要声明几乎所有变量。 C和C ++都要求在使用变量之前声明变量,因此到目前为止,几乎每个语句都是非法的。
只是瞥一眼你的程序,看起来还有许多其他问题也可以打破它。在这一点上,如果您尝试使用编译器的输出自行调试将会更有用,因为我确信到目前为止我发现的所有错误都会被任何编译器发现。
如果您仍然遇到问题,则需要提出更具体的问题,最好还是编译器的输出\错误消息。
答案 1 :(得分:0)
cin << counterDEPTH;
将其更改为
cin >> counterDEPTH;
并以类似方式更改其他人
答案 2 :(得分:0)
您已将cin
和cout
同时写为<<
。 cin
必须使用>>
。
答案 3 :(得分:0)
这是你的全部代码吗?您需要声明要存储用户输入的变量。此外,Yes / No / Marble / Granite / Quartz / Quartite也未在任何地方定义。
#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;
答案 4 :(得分:0)
将cin
语句更改为>>
,例如
cin&gt;&gt; counterDEPTH;
在break;
语句的每个case
块末尾添加switch
。