Advertisement
Guest User

flehsememe

a guest
Sep 16th, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1.  
  2.  
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int main(int argc, const char * argv[])
  7. {
  8.    
  9.    
  10.     cout.setf(ios::fixed);
  11.     cout.setf(ios::showpoint);
  12.     cout.precision(2);
  13.    
  14.    
  15.     int userinput;
  16.    
  17.     cout << "A packet of candie costs $1.50. You have inserted $0.00. Please insert coins:";
  18.     cin >> userinput;
  19.    
  20.    
  21.    
  22.    
  23.     switch (userinput)
  24.     {
  25.    
  26.         case 'n':
  27.         {
  28.             userinput = 0.05;
  29.             break;
  30.         }
  31.            
  32.         case 'd':
  33.         {
  34.             userinput = 0.10;
  35.             break;
  36.         }
  37.            
  38.         case 'q':
  39.         {
  40.             userinput = 0.25;
  41.             break;
  42.         }
  43.            
  44.         case 'D':
  45.         {
  46.             userinput = 1.00;
  47.             break;
  48.         }
  49.            
  50.         default:
  51.         {
  52.             cout << "'" << userinput << "' is not a valid coin.";
  53.         }
  54.             break;
  55.     }
  56.    
  57.         int i;
  58.        
  59.         for (i = 0; i <= userinput; i++)
  60.         {
  61.        
  62.         cout << "A packet of candie costs $1.50. You have inserted $" << userinput << ".";
  63.         cout << "Please insert coins: ";
  64.         cin >> userinput;
  65.            
  66.         userinput = userinput + userinput;
  67.         }
  68.    
  69.  
  70.     return (0);
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement