Windwaker222
In Runtime
- Messages
- 379
It's time to play....Simplify my crappy code
The winner gets..Well nothing
Anyway I just learned C++ today since I want to be a programmer when I am older. The program is basically letting you buy stuff. There isnt a limit since I haven't figured out how yet. I just wanted to know is there an easier, but still simple way to write the code
The winner gets..Well nothing
Anyway I just learned C++ today since I want to be a programmer when I am older. The program is basically letting you buy stuff. There isnt a limit since I haven't figured out how yet. I just wanted to know is there an easier, but still simple way to write the code
Code:
#include <iostream>
using namespace std;
int main()
{
int cash=5000;
int input;
int a=700;
int b=300;
int c=350;
int d=1400;
int e=1100;
int f=260;
int g=79;
int h=400;
int i=599;
int j=59;
cout << "Welcome! You are now using the most automated purchasing program in the world. This program has been created to ease you through the process of spending money.\n\n";
cout << "You have " << cash << "$ to spend\n\n";
do{
cout << "1. nVidia 6800 Ultra : 700$\n";
cout << "2. nVidia 6600 GT : 300$\n";
cout << "3. AMD 64 3500+ : 350$\n";
cout << "4. Intel Pentium 4 3.4GHz EE : 1400$\n";
cout << "5. AMD 64 FX-55 : 1100$\n";
cout << "6. Western Raptor 10K 74GB SATA 16MB : 260$\n";
cout << "7. Liteon 16xDVD-RW : 79$\n";
cout << "8. Apple Ipod 20GB : 400$\n";
cout << "9. Apple Mac Mini : 599$\n";
cout << "10. Doom 3 : 59$\n\n";
cout << "Please enter your selection : ";
cin >> input;
cin.ignore();
switch ( input ) {
case 1:
cout << "\n\nYou now have " << (cash=cash-a) <<"$ left.\n\n";
break;
case 2:
cout << "\n\nYou now have " << (cash=cash-b) <<"$ left.\n\n";
break;
case 3:
cout << "\n\nYou now have " << (cash=cash-c) <<"$ left.\n\n";
break;
case 4:
cout << "\n\nYou now have " << (cash=cash-d) <<"$ left.\n\n";
break;
case 5:
cout << "\n\nYou now have " << (cash=cash-e) <<"$ left.\n\n";
break;
case 6:
cout << "\n\nYou now have " << (cash=cash-f) <<"$ left.\n\n";
break;
case 7:
cout << "\n\nYou now have " << (cash=cash-g) <<"$ left.\n\n";
break;
case 8:
cout << "\n\nYou now have " << (cash=cash-h) <<"$ left.\n\n";
break;
case 9:
cout << "\n\nYou now have " << (cash=cash-i) <<"$ left.\n\n";
break;
case 10:
cout << "\n\nYou now have " << (cash=cash-j) <<"$ left.\n\n";
break;
case q:
default :
cout << "\n\nThat is not a valid item! You still have " << cash << "$ to spend!\n\n";
break;
}
} while( input != 0);
cin.get();
}