| | |
error trap, and some more basics
Thread Solved |
•
•
Join Date: Feb 2010
Posts: 60
Reputation:
Solved Threads: 0
Im trying to figure out how to error trap this program so if the user doesnt put in a valid response then a message will cum up and they will go back 2 the beginning until they do it correctly.
also i want to subtract the money they spend and tell them their remaining amount, also i want to keep track of the number of items they purchase.
when i do it all that comes up is a whole bunch of numbers.
can anyone help when you compile this program i want this format but the numbers arent right
can anyone help?
/* SIUE's bookstore is having aspecail sale on tiems embossed with the cougar logo. For a limited time, three items, mugs, teeshirts, and pens
are offered at a reduced rate with tax included to simplify the sales. Mugs are going for $2.50, teeshirts for $9.50 and pens for 75
cents. Coincidentally, your parents (or spouse, friend, coworker, or other person you know off-campus) just gave you $30.00 to buy SIUE
stuff for them.*/
#include<iostream>
using namespace std;
int main()
{
char symb;
int item_purch, numb_item_purch, quit;
double mug, teeshirt, pen, tot_mon, curr_cash, mon_spent;
cout << "What do you want to buy today?\n";
cout << "You have 30 dollars to spend.\n";
cout << " A) Mugs $2.50 " << endl;
cout << " B) teeshirt $9.50 " << endl;
cout << " C) Pens .75 cents " << endl;
cout << " D) Quit" << endl;
cout << " Enter your letter and press Return when finished" << endl;
cin >> symb;
switch (symb)
{
case 'A':;
case 'a':;
cout << " You have choosen A) mugs for $2.50 \n";
mug = 2.50;
cout << " You have " << curr_cash << " remaining \n ";
tot_mon = 30;
curr_cash = tot_mon - mug;
cout << " You have purchased " << numb_item_purch << " today \n ";
numb_item_purch = item_purch + 1;
break;
case 'B':;
case 'b':;
cout << " You have choosen B) teeshirt for $9.50 ";
teeshirt = 9.50;
break;
case 'C':;
case 'c':;
cout << " You have choosen C) Pens for .75 cents ";
pen = .75;
break;
case 'D':;
case 'd':;
cout << " You have choosen D) which means you want to Quit" << endl;
quit = 0;
break;
}
cin >> tot_mon;
curr_cash = tot_mon - mon_spent;
cin >> curr_cash;
cin >> mon_spent;
return 0;
}
also i want to subtract the money they spend and tell them their remaining amount, also i want to keep track of the number of items they purchase.
when i do it all that comes up is a whole bunch of numbers.
can anyone help when you compile this program i want this format but the numbers arent right
can anyone help?
/* SIUE's bookstore is having aspecail sale on tiems embossed with the cougar logo. For a limited time, three items, mugs, teeshirts, and pens
are offered at a reduced rate with tax included to simplify the sales. Mugs are going for $2.50, teeshirts for $9.50 and pens for 75
cents. Coincidentally, your parents (or spouse, friend, coworker, or other person you know off-campus) just gave you $30.00 to buy SIUE
stuff for them.*/
#include<iostream>
using namespace std;
int main()
{
char symb;
int item_purch, numb_item_purch, quit;
double mug, teeshirt, pen, tot_mon, curr_cash, mon_spent;
cout << "What do you want to buy today?\n";
cout << "You have 30 dollars to spend.\n";
cout << " A) Mugs $2.50 " << endl;
cout << " B) teeshirt $9.50 " << endl;
cout << " C) Pens .75 cents " << endl;
cout << " D) Quit" << endl;
cout << " Enter your letter and press Return when finished" << endl;
cin >> symb;
switch (symb)
{
case 'A':;
case 'a':;
cout << " You have choosen A) mugs for $2.50 \n";
mug = 2.50;
cout << " You have " << curr_cash << " remaining \n ";
tot_mon = 30;
curr_cash = tot_mon - mug;
cout << " You have purchased " << numb_item_purch << " today \n ";
numb_item_purch = item_purch + 1;
break;
case 'B':;
case 'b':;
cout << " You have choosen B) teeshirt for $9.50 ";
teeshirt = 9.50;
break;
case 'C':;
case 'c':;
cout << " You have choosen C) Pens for .75 cents ";
pen = .75;
break;
case 'D':;
case 'd':;
cout << " You have choosen D) which means you want to Quit" << endl;
quit = 0;
break;
}
cin >> tot_mon;
curr_cash = tot_mon - mon_spent;
cin >> curr_cash;
cin >> mon_spent;
return 0;
}
•
•
Join Date: Feb 2010
Posts: 60
Reputation:
Solved Threads: 0
•
•
•
•
I'll give you the benefit of time this time. You received an infraction warning about CODE tags 7 minutes before posting this. Last warning.
just let me know cuz this site is pimp it helps me out alot
0
#5 Feb 8th, 2010
•
•
•
•
what are the code tags ? i will put them on there if i knew how an error comes up when i do it. arent they just codes for people too type in so when someone to help people they use the code tags? r am i wrong?
just let me know cuz this site is pimp it helps me out alot
[CODE]
Click on it, then something like this would appear:
Then, type your code in between them and that's it!
"Show me your code and I will tell you who you are.."-Tkud
0
#6 Feb 8th, 2010
•
•
•
•
what are the code tags ? i will put them on there if i knew how an error comes up when i do it. arent they just codes for people too type in so when someone to help people they use the code tags? r am i wrong?
just let me know cuz this site is pimp it helps me out alot
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
![]() |
Similar Threads
- error trap (C++)
- ftp-> quit fails with Bad file number error for some servers (Perl)
- Handling Notepad By Visual Basic 6.0 (Visual Basic 4 / 5 / 6)
- Homework help - Using function to create a triangle (C++)
- 1 d Arrays Homework Help (C++)
- help me with this (Visual Basic 4 / 5 / 6)
- Please help with assignment (C++)
- XP Installtion Problem trap 00000006 Exception (Windows NT / 2000 / XP)
- audio level detection (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: Short Shuffle for 1D Array using C++
- Next Thread: Display the bits representing a double precision floating point number
Views: 245 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for C++
algorithm api array arrays assignment beginner binary browser c++ c/c++ calculator char class classes code compile compiler constructor conversion convert count delete desktop display dll dynamic encryption error exception file files fstream function functions game givemetehcodez graph gui helpwithhomework homework i/o iamthwee input int integer lazy library linked-list linker list loop looping loops math matrix member memory newbie news number object objects opengl output parameter path pointer pointers problem program programming project random read recursion recursive reference sort sorting spoonfeeding string strings struct student studio template templates text time tree undefined variable vc++ vector video visual win32 window windows winsock






