problems getting output with int and switch

This is a discussion on problems getting output with int and switch within the C++ Programming forums, part of the General Programming Boards category; #include <iostream.h> #include <iomanip.h> int main () { int inch; int extop; int costtop; int numtop; double subtot; double tot; ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    9

    problems getting output with int and switch

    #include <iostream.h>
    #include <iomanip.h>

    int main ()

    {

    int inch;
    int extop;
    int costtop;
    int numtop;
    double subtot;
    double tot;
    int chex;
    double chezcost;
    int piztop;
    int price;
    int top;


    cout<< "6 inch personal $3.15 + .35 per topping\n"<< endl
    << "10 inch small $5.70 + .55 per topping\n"<< endl
    << "14 inch medium $7.45 + .70 per topping\n"<< endl
    << "16 inch large $9.15 + .85 per topping\n"<< endl
    << "18 inch exlarge $11.15+ $1.40 per topping\n\n"<< endl;

    cout << "Enter size 6, 10, 14 etc..\n" << endl;
    cin>> inch;
    cout << " Extra toppings 1 = Yes -- 2 = No \n"<<endl;
    cin>> extop;
    cout <<"Extra Cheese 1 = Yes -- 2 = No"<<endl;
    cin>> chex;


    switch (inch)

    {
    case 6: price = 3.15;
    break;

    case 10: price = 5.70;
    break;

    case 14: price = 7.45;
    break;

    case 16: price = 9.15;
    break;

    case 18: price = 11.15;
    break;

    case "\n":
    }

    cout << "inch " << inch<<endl;
    cout <<" price "<< setprecision(2)<< price <<endl;
    if (extop !=2)
    {
    cout << "How many toppings"<< endl;
    cin>> numtop;

    switch (inch)

    {
    case 6:top =.35;
    break;

    case 10:top =.55;
    break;

    case 14:top =.70;
    break;

    case 16:top =.85;
    break;

    case 18:top = 1.40;
    break;
    }


    cout <<" top "<< setprecision(2) <<top <<endl;//price of topping per size

    costtop = (numtop * top);
    cout<< "costtop" << setprecision(2)<<costtop<< endl;//cost of topping(s)

    piztop= costtop + price;
    cout<< "piztop"<< setprecision(2)<<piztop<< endl;//pizza and toppings cost



    if (chex = 1)
    {

    if (inch = 6 || 10)
    {
    chezcost = 1.10; //excheese per inch
    }
    else
    {
    chezcost = 2.00;
    }


    }

    cout << "chezcost\n\n"<< setprecision(2)<<chezcost <<endl;// cost of excheese

    subtot = piztop + chezcost;
    cout<< "Subtotal"<< setprecision(2)<<subtot<<endl;

    cout<< "\n";

    tot = (subtot*.675)+subtot;
    cout<< "Total"<< setprecision(2)<<tot<<"\n\n";

    return 0;
    }

    First problem, price is being output as a neg number

  2. #2
    _ Munkey01's Avatar
    Join Date
    Dec 2002
    Posts
    280
    I am not sure of why it would be showing as negative, but you are using decimal values so instead of using type int with variables that deal with decimals, use a float type so they are supported.

    ALSO, USE CODE TAGS!!!!!!

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    9
    This is not the first time I've been told this but what are code tags.

    Please!!!! provide an example


    Lynn

  4. #4
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    [ code] // .... [/ code]

    Without the extra whitespace, of course! It'll look like this
    Code:
     // ....
    Really improves readability...
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109

  6. #6
    Lurker
    Guest
    Also...
    Code:
    if (chex = 1)
    {
    
    if (inch = 6 || 10)
    should be
    Code:
    if (chex == 1)
    {
    
    if (inch == 6 || inch == 10)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 04:45 AM
  2. Replies: 26
    Last Post: 11-30-2007, 03:51 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 04:42 PM
  5. Switch/case Problems (long code in post)
    By Wraithan in forum C++ Programming
    Replies: 2
    Last Post: 12-01-2005, 06:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21