Help with case [switch statement] code
Apr 3, 2012 at 11:20pm UTC
Having an issue with this code
Once the program runs:
It's not allowing for the 2nd input line to take place
It's not calculating the basePrice of the given items
------------------Here is the code--------------------
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
#include <iostream>
#include <string.h>
using namespace std;
//protoypes
void input();
void calcTotal();
void printReceipt();
//Global variables
double numDraws = 0;
double total = 0;
char woodType[6] = " " ;
double tax = .06;
double drawTotal = 0;
int basePrice = 0;
int main()
{
char woodType[6] = " " ;
//case structure
int selection = 0; //case control variable
//Process
{
cout << "What kind of wood would you like to use to build your desk?" << endl;
cout << "Pine desks are $100" << endl;
cout << "Oak desks are $140" << endl;
cout << "All other wood desks are $180" << endl;
cout << "In addition, a $30 surcharge is added for each drawer" << endl << endl;
}
switch (tolower(woodType[6]))
{
case 1:
basePrice = 100;
strcpy_s(woodType, "Pine" ); // woodType = pine
break ;
case 2:
basePrice = 140;
strcpy_s(woodType, "Oak" ); // woodType = oak
break ;
case 3:
basePrice = 180;
strcpy_s(woodType, "other" ); // woodType = other
break ;
} //End of case
input();
calcTotal();
printReceipt();
system("pause" );
return 0;
}
void input()
{
cout << "What type of wood would you like to buy? " << " " << endl;
cin >> woodType[6];
cout << "How many draws would you like to buy? " << endl;
cin >> numDraws;
}
void calcTotal()
{
drawTotal = (numDraws*30);
total = (numDraws*30) + basePrice + tax;
}
void printReceipt()
{
cout << "Total sales tax: " << tax << endl;
cout << "Total price for the Draws: " << drawTotal << endl;
cout << "Over all total price: $" << total << endl <<endl;
}
Last edited on Apr 3, 2012 at 11:27pm UTC
Topic archived. No new replies allowed.