Advertisement
Guest User

eminv1.0

a guest
Nov 21st, 2017
63
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 namespace std;
  4.  
  5. const int MaxN = 100;
  6.  
  7. struct CarT{
  8.     string date;
  9.     int amount;
  10.     int quantities;
  11. };
  12.  
  13. int main()
  14. {
  15.     //declaration
  16.     CarT car[MaxN];
  17.     int N;
  18.     bool exist;
  19.     string when;
  20.     int sum;
  21.     int cnt;
  22.  
  23.  
  24.     //input
  25.     bool error1 = false;
  26.     do{
  27.         cout<<"How many items are there?: ";
  28.         cin>>N;
  29.         error1 = ((N<1) || (N>MaxN));
  30.         if(error1){
  31.             cout<<"Not good. Please gove another value. "<<endl;
  32.             }
  33.  
  34.     }while(error1);
  35.  
  36.     for(int i = 0; i<N; i++){
  37.         cout<<" What is the "<<i+1<<" item's date?: ";
  38.         cin>>car[i].date;
  39.         bool error2 = false;
  40.         do{
  41.         cout<<" What is the "<<i+1<<" item's amount?: ";
  42.         cin>>car[i].amount;
  43.         error2 = (car[i].amount < 0);
  44.         if(error2){
  45.             cout<<"Not good. Please give another value. "<<endl;
  46.         }
  47.         }while(error2);
  48.         bool error3 = false;
  49.         do{
  50.         cout<<" What is the "<<i+1<<" item's quantities?: ";
  51.         cin>>car[i].quantities;
  52.         error3 = (car[i].quantities < 0);
  53.         if(error3){
  54.             cout<<"Not good. Please give another value. "<<endl;
  55.         }
  56.         }while(error3);
  57.  
  58.  
  59.     }
  60.  
  61.     cout<<"\n";
  62.     //algorithm
  63.  
  64.     int i = 0;
  65.     while((i <= N) && (car[i].amount != 20000)){
  66.         i+=1;
  67.     }
  68.     exist = (i<=N);
  69.  
  70.     sum = 0;
  71.     for(int i = 0; i<N; i++){
  72.         sum = sum + car[i].amount;
  73.     }
  74.  
  75.  
  76.     //output
  77.     if(exist){
  78.         when = car[i].date;
  79.         cout<<"We payed exactly 20000 on the "<<when<<" date."<<endl;
  80.     }else{
  81.         when = "never";
  82.         cout<<when<<endl;
  83.     }
  84.  
  85.     cout<<"The amount that we spent on gasoline is: "<<sum<<endl;
  86.  
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement