-4

So I'm attempting to create a program which, essentially, asks the user for a variety of inputs and outputs depending on the user's choices. I'm doing this using the switch method as well as cin. For some reason, it's not letting me compile. Can anyone offer insight as to what I'm doing wrong here? Thanks!

   #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;
     }
Physics
  • 1
  • 1
  • [Is it this?](http://stackoverflow.com/questions/92396/why-cant-variables-be-declared-in-a-switch-statement) – chris Sep 23 '12 at 19:23
  • Are you allowed to talk about the "reason it's not letting you compile"? Does it switch off your neighbourhood's power? Is it holding your husband hostage? Is it hitting you in the face with electrons? – Kerrek SB Sep 23 '12 at 19:23
  • You can't use `&` to chain outputs. You need more `<<`. – chris Sep 23 '12 at 19:26
  • `double newcost = cost; double newcost = (.15 * newcost);` There's another one. – chris Sep 23 '12 at 19:28
  • 1
    -1, Sorry but there are just too many things wrong with this code. – Borgleader Sep 23 '12 at 19:28
  • Agreed. No single answer is going to get them all, so it makes it very hard for one to be acceptable. Most of these are things you learn early from going through C++, whether in a class, or from a book, or however you learn. – chris Sep 23 '12 at 19:29

5 Answers5

1

To begin with, you need to declare almost all of your variables. C and C++ both require variables to be declared before they are used, so almost every statement you have so far is illegal.

Just from glancing at your progam it looks like there are a host of other issues that could break it as well. At this point it's going to be much more use if you try to debug using the output of your compiler by yourself, as I'm sure that all the errors I've spotted so far would have been spotted by any compiler.

If you're still having problems then, you need to ask more specific questions, preferably along with the output\error messages from your compiler.

AdamHarries
  • 335
  • 2
  • 11
0
cin << counterDEPTH;

Change it to

cin >> counterDEPTH;

and change others similarly

0

You have written both cin and cout with <<. cin has to use >>.

CoffeeRain
  • 4,460
  • 4
  • 31
  • 50
Ravindra Bagale
  • 17,226
  • 9
  • 43
  • 70
0

Is this all of your code? You need to declare the variables you are storing user input to. Also, Yes/No/Marble/Granite/Quartz/Quartite aren't defined anywhere either.

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

Your switch statement also needs breaks.

case Marble:
    double cost = 92.99;
    break;
case Granite:
    double cost = 78.99;
    break;
James McCracken
  • 15,488
  • 5
  • 54
  • 62
0
  1. Change cin statements to have >>, e.g.

    cin >> counterDEPTH;

  2. add break; at end of each case block of your switch statements.

Curious
  • 2,783
  • 3
  • 29
  • 45