Line 13:
brand
and
model
are unused.
Line 16: You're trying to assign a string to an integer.
Line 18: You need a semicolon at the end.
Lines 79-85 are indented as though they should execute inside the else at line 77, but they aren't enclosed in braces, so they always execute.
The if/else ladder has a lot of duplicate code. I would have the ladder just compute the discount. Then after you've computed the discount, you can print the appropriate output.
Since you didn't post in the beginners forum, I'll assume that you know about functions and methods. I'd create methods of the AClass class to read the info, compute the discount and print the results. Also, AClass should contain the brand, model, year, and original price of the car.
Here is a partial implementation that puts all this together. You'll need to write the code where the comments say "TBD"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include <iostream>
using namespace std;
class AClass
{
public:
string brand, model;
int year;
int price;
void read();
double computeDiscount();
void print();
}; // for the class assign
// Prompt the user for brand, model, year and original price
void
AClass::read()
{
// TBD
}
// Return the discount for the model year. This returns the fractional
// discount. i.e., 10% is returned as 0.10.
double
AClass::computeDiscount()
{
// TBD
}
// Compute the discount and Print the info for this car
void
AClass::print()
{
double discount = computeDiscount();
cout << "\nWELCOME TO PANDU CEPAT AUTO !" << endl;
cout << "For model " << year << '\n';
//TBD
}
int
main()
{
AClass MyCar;
MyCar.read();
MyCar.print();
}
|