Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/137.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;-使用开关的用户输入和输出?_C++_Input_Switch Statement - Fatal编程技术网

C++ C++;-使用开关的用户输入和输出?

C++ C++;-使用开关的用户输入和输出?,c++,input,switch-statement,C++,Input,Switch Statement,因此,我试图创建一个程序,它本质上要求用户根据用户的选择提供各种输入和输出。我正在使用切换方法以及cin来执行此操作。出于某种原因,它不允许我编译。有人能告诉我我做错了什么吗?谢谢 #include <iostream> using namespace std; int main() { cout << "Welcome to my countertop store.\n" << "Before runn

因此,我试图创建一个程序,它本质上要求用户根据用户的选择提供各种输入和输出。我正在使用切换方法以及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;
     }
#包括
使用名称空间std;
int main()
{
库特

并且同样地更改其他人

您已经用
编写了
cin
cout

这是您的全部代码吗?您需要声明存储用户输入的变量。此外,是/否/大理石/花岗岩/石英/石英岩也没有在任何地方定义

#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;

首先,你必须声明你所有的变量。C和C++都需要变量在使用之前声明,所以你现在的每个语句都是非法的。 只要看一眼你的程序,就会发现还有很多其他问题可能会破坏它。在这一点上,如果你自己尝试使用编译器的输出进行调试,它会有更大的用处,因为我相信我迄今为止发现的所有错误都会被任何编译器发现

如果您仍然有问题,那么您需要提出更具体的问题,最好与编译器的输出\错误消息一起提出

  • cin
    语句更改为具有
    >
    ,例如

    cin>>反深度

  • break;
    添加到
    switch
    语句的每个
    case
    块的末尾


  • 你可以谈论“它不让你编译的原因”吗?它会关闭你邻居的电源吗?它会劫持你丈夫吗?它会用电子打你的脸吗?你不能用
    &
    来链接输出。你需要更多
    双倍新成本=成本;双倍新成本=(.15*newcost)
    还有一个。-1,对不起,这个代码有太多问题。谢谢。我会检查一下,然后再给你回复。
    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;
    
    case Marble:
        double cost = 92.99;
        break;
    case Granite:
        double cost = 78.99;
        break;