Advertisement
MrSnoopy

Cpp Devbook prasečina

Mar 31st, 2014
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using std::cout;
  4. using std::cin;
  5. using std::endl;
  6.  
  7. int  main(int argc, char*argv []){
  8.  
  9.     //declare section
  10.  
  11.     //start money
  12.     int money = 5000000;
  13.  
  14.     //item counters
  15.     int audi = 0;
  16.     int bmw = 0;
  17.     int subaru = 0;
  18.  
  19.     //menu choice (dont neednt to initialize)
  20.     char choice = '0';
  21.  
  22.     //--declare section end--
  23.  
  24.  
  25.     //Do, while not ended by choice = 0
  26.     do{
  27.         //how much car to buy
  28.         int count =0;
  29.  
  30.         cout << "Welcome to car store!" << endl;
  31.         cout << "You have " << endl;
  32.         cout << "Audi's: " << audi << endl;
  33.         cout << "BMW's:  " << bmw << endl;
  34.         cout << "Subaru's: " << subaru << endl;
  35.  
  36.         cout << "Money: " << money << endl;
  37.  
  38.         cout << "Which type do you want?" << endl;
  39.         cout << "(S)ubaru (25459 per car) - (B)MW (31596 per car) - (A)udi (36498 per car)?" <<endl;
  40.         cout << "Type '0'to leave the game! " << endl;
  41.  
  42.         cin >> choice;
  43.  
  44.         //dont write the same code twice or more  times ;)
  45.         if(choice != '0'){
  46.             cout << "How much? ";
  47.             cin >> count;
  48.         }
  49.  
  50.         switch(choice){
  51.         case 's':
  52.             //without break continues to case bellow !! not as correct as can be
  53.         case 'S':
  54.             money -= 25459 * count;
  55.             cout << "You bought subaru! Your current money is: " << money << endl;
  56.             subaru +=1 * count;
  57.             break;
  58.  
  59.         case 'b':
  60.                 //without break continues to case bellow
  61.         case 'B':
  62.             money -= 31596 * count;
  63.             cout << "You bought BMW! Your current money is: " << money << endl;
  64.             bmw+=1 * count;
  65.             break;
  66.         case 'a':
  67.                 //without break continues to case bellow
  68.         case 'A':
  69.             money -= 36498 * count;
  70.             cout << "You bought Audi! Your current money is: " << money << endl;
  71.             audi+=1 * count;
  72.             break;
  73.         default:
  74.             cout << "Wrong choice, repeat please" << endl << endl;
  75.         }
  76.  
  77.  
  78.     }while(choice != '0');
  79.  
  80.  
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement