using namespace std; #include #include main() { int type; //to store the type to traffic violation int fine; //to store the amount of fine against violation type int duration; //to store the number of days passed till challan date int challan; //to store the challan against violation type and number of days passed char choice = 'y'; //to get user's choice whether to calculate another challan or not do { system("cls"); //clear screen function //following 4 lines of code are printing information about how to select a specific traffic violation cout << "******* CHALLAN CALCULATOR FOR TRAFFIC VIOLATIONS *******" << endl <> type; //if user enters anything except 1, 2, or 3, the error message will be shown and do-while loop will start again due to continue statement if(type <1 || type > 3) { cout << endl <<"Enter a valid type of traffic violation"; //getch() function will get a character from user. Its used here to hold the output screen before executing continue statement so that user can see the error message before screen gets cleared getch(); continue; } //Taking input for number of days passed till challan date in variable duration cout << "Enter the number of days passed till challan date : "; cin >> duration; //Checking value of "type" variable and assigning corresponding amount of fine to variable "fine" switch(type) { case 1: fine = 500; break; case 2: fine = 300; break; case 3: fine = 200; break; } //Calculating total challan according to number of days passed till challan date if(duration <=10) { challan = fine; } else if(duration <=30) { challan = fine * 2; } else { challan = fine * 2 + (fine / 2); } cout << "The total challan is Rs." << challan << endl << endl; //taking user's choice whether to calculate another challan or not cout << "Do you want to calculate another challan? (y/n) : "; cin >> choice; //loop will start again only if the choice is y or Y }while(choice == 'y' || choice == 'Y'); }