amlxv

here

Nov 13th, 2019 (edited)
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.    char regNum[50], addCarsResult, hiRegNum[50];
  8.    double price, totalPrice = 0, avgPrice, hiPrice = 0;
  9.    int i, cheapCars = 0;
  10.    bool addCars = true;
  11.  
  12.    for(i=1; i>0; i++ && !addCars){
  13.  
  14.     cout << "Enter the car registration number : " ;
  15.     cin >> regNum;
  16.     cout << "Enter the car price : RM ";
  17.     cin >> price;
  18.  
  19.     if(price < 30000){
  20.  
  21.         cheapCars++;
  22.  
  23.     }
  24.  
  25.     if(price > hiPrice) {
  26.  
  27.         hiPrice = price;
  28.         strcpy(hiRegNum, regNum);
  29.  
  30.     }
  31.  
  32.     totalPrice = totalPrice + price;
  33.  
  34.     cout << "Do you want to add another cars? (Y/N) : ";
  35.     cin >> addCarsResult;
  36.     cout << endl;
  37.  
  38.     if(addCarsResult == 'Y' || addCarsResult == 'y'){
  39.  
  40.         addCars;
  41.  
  42.     } else {
  43.  
  44.         addCars = !addCars;
  45.  
  46.     }
  47.  
  48.     if(addCars == false){
  49.  
  50.         break;
  51.  
  52.     }
  53.  
  54.    }
  55.  
  56.    avgPrice = totalPrice / i;
  57.  
  58.    cout << "Total Price = RM " << totalPrice << endl;
  59.    cout << "Average Price : RM " << avgPrice << endl;
  60.    cout << "The car with highest price is " << hiRegNum << " (Registration Number). The Price is RM " << hiPrice << endl;
  61.    cout << "There are "<< cheapCars << " cheap cars with price below than RM30,000.00 " << endl;
  62.  
  63.    return 0;
  64.  
  65. }
Add Comment
Please, Sign In to add comment