Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int MaxN = 100;
- struct CarT{
- string date;
- int amount;
- int quantities;
- };
- int main()
- {
- //declaration
- CarT car[MaxN];
- int N;
- bool exist;
- string when;
- int sum;
- int cnt;
- //input
- bool error1 = false;
- do{
- cout<<"How many items are there?: ";
- cin>>N;
- error1 = ((N<1) || (N>MaxN));
- if(error1){
- cout<<"Not good. Please gove another value. "<<endl;
- }
- }while(error1);
- for(int i = 0; i<N; i++){
- cout<<" What is the "<<i+1<<" item's date?: ";
- cin>>car[i].date;
- bool error2 = false;
- do{
- cout<<" What is the "<<i+1<<" item's amount?: ";
- cin>>car[i].amount;
- error2 = (car[i].amount < 0);
- if(error2){
- cout<<"Not good. Please give another value. "<<endl;
- }
- }while(error2);
- bool error3 = false;
- do{
- cout<<" What is the "<<i+1<<" item's quantities?: ";
- cin>>car[i].quantities;
- error3 = (car[i].quantities < 0);
- if(error3){
- cout<<"Not good. Please give another value. "<<endl;
- }
- }while(error3);
- }
- cout<<"\n";
- //algorithm
- int i = 0;
- while((i <= N) && (car[i].amount != 20000)){
- i+=1;
- }
- exist = (i<=N);
- sum = 0;
- for(int i = 0; i<N; i++){
- sum = sum + car[i].amount;
- }
- //output
- if(exist){
- when = car[i].date;
- cout<<"We payed exactly 20000 on the "<<when<<" date."<<endl;
- }else{
- when = "never";
- cout<<when<<endl;
- }
- cout<<"The amount that we spent on gasoline is: "<<sum<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement