-4

因此,我正在尝试创建一个程序,该程序本质上会根据用户的选择要求用户提供各种输入和输出。我正在使用 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;
     }
4

5 回答 5

1

首先,您需要声明几乎所有的变量。C 和 C++ 都要求在使用变量之前声明它们,因此到目前为止几乎所有的语句都是非法的。

仅仅看一眼你的节目,似乎还有许多其他问题也可能破坏它。在这一点上,如果您尝试自己使用编译器的输出进行调试,它将更加有用,因为我确信到目前为止我发现的所有错误都会被任何编译器发现。

如果您仍然遇到问题,则需要提出更具体的问题,最好是与编译器的输出\错误消息一起提出。

于 2012-09-23T19:27:29.977 回答
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;
于 2012-09-23T19:26:35.780 回答
0
  1. cin将语句更改为 have >>,例如

    cin >> 计数器深度;

  2. 在每个语句块的break;末尾添加。caseswitch

于 2012-09-23T19:28:44.070 回答
0
cin << counterDEPTH;

将其更改为

cin >> counterDEPTH;

并类似地改变其他人

于 2012-09-23T19:24:03.200 回答
0

你已经写了cin和。必须使用.cout<<cin>>

于 2012-09-23T19:24:42.817 回答