Thread: c program help :>

1. c program help :>

I need help with figuring out an assignment I have to do.. I can't figure out how to make the program check for the difference between classic car and miles as well as do the other things it already is doing. I Just need to get to the right direction, can't quite figure out what I haven't done yet or I am doing wrong..

Here's the question:
There are many factors to consider before purchasing a used car.
Three major factors that affect the ultimate selling price of a
used car are:

Make (manufacturer), Year, and the number of Kilometers or Miles the
car has been driven.

Specifications:
For your first programming assignment this semester, you are to write a
C program that helps customers estimate the selling price of a used car
based on the factors listed above for a select number of automobile
manufacturers (see table below).

Make Depreciation/Year Depreciation/Kilometer
---------- ----------------- ---------------
Porsche \$ 650.00 \$0.03
Chevrolet \$1950.00 \$0.11
Volkswagon \$1700.00 \$0.08
BMW \$ 950.00 \$0.05
Audi \$1200.00 \$0.06
Honda \$1350.00 \$0.07
Ford \$2100.00 \$0.09
Mercedes \$ 875.00 \$0.05

Depreciation (the decrease in value) of an automobile occurs both by
year AND by kilometers driven. (eg.) A 1 year old Porsche that has been driven
5 kilometers will depreciate by \$650.15 (1 * 650.00 + 5 * 0.03).

Your program should begin by asking the user for five pieces of data:

1. The current year (a whole number),
2. The make of the USED car (a whole number),

1 for Porsche,
2 for Chevrolet,
3 for Volkswagon,
4 for BMW,
5 for Audi,
6 for Honda,
7 for Ford,
8 for Mercedes

3. The year the car was manufactured (a whole number),

4. The original selling price (M.S.R.P.) of the car
(a floating point number),

5. The number of kilometers or miles (Odometer reading)
the car has been driven (a whole number).

NOTE: Because they are manufactured in the U.S., if the make chosen by the
user is 2 (Chevrolet) or 7 (Ford), you are to ask the user how many
"Miles" the car has been driven, otherwise you are to ask the user for
the number of Kilometers.

Also, the above table lists distance depreciation values in
\$Dollars per Kilometer therefore be careful when calculating totals for
automobiles that have their odometer reading entered in Miles.
You may assume that 1 Mile = 1.6 KM.

Your program should then process the information, perform the necessary
calculations, and display for the user, what the estimated selling price
of the car is (in the following format):

Automobile Information:
Make: [Make]
Year: [Year]
Odometer: [Kilometers or Miles]
Depreciation: [dispayed as a percentage (%)]

Selling Price: \$[Estimated Cost of Used Car]
Tax: \$[GST (5%) and PST (8%)]
----------
Total: \$[Final selling price]

Where Make, Year, and Kilometers or Miles are the values entered
by the user, and Depreciation (percentage of the original
value the car has depreciated before tax), Selling Price, Tax,
and Total (Selling Price + Tax) are all calculated values.
If the final selling price of ANY vehicle is less than or
equal to \$0.00, you are not to display any of this
information, but instead are to display ONLY the following line:

"I wouldn't buy this car if I were you!!!"

In addition, because some car makes (and then, only certain
years within those Make's) are considered to be "classic's"
(since so few of those cars were manufactured), the ultimate
value of these cars will depreciate as follows:

+ Classic automobiles will only depreciate by the amount of
Kilometers driven at a rate equal to 1/2 (one half) of that listed
in the chart above, and will not depreciate by Year,
regardless of how old they are!

+ In addition, \$10,000 is to be added to the final selling
price only after depreciation calculations have been performed,
but before both the percent depreciation and tax amounts are
calculated. If after the depreciation calculations have been
performed on a classic car, you determine that the selling price
is less than or equal to \$0.00, then the selling price of that
classic car (before tax) should be set to \$10,000.00
Thus, a "classic" car can never be worth less than \$10,000.00
regardless of the number of Kilometers or Miles it has been driven
or how old it is!

+ Classic automobile makes (and years within those makes) are:
Porsche (1948, 1963 and 1965)
Chevrolet (1955 and 1957)
Ford (1931, 1957, 1964, and 1965)
BMW (1955)

(eg.) A 1948 Porsche is a "classic", but a 1949 Porsche is not!
(eg.) For BMW's, only those manufactured in 1955 would be considered
to be classic.

If the car is a classic, an extra line of output should be
displayed notifying the user of this fact. Also, because
classic cars have \$10,000.00 added to their selling price,
it will be possible to have a negative depreciation
indicating that the vehicle has actually appreciated
(increased in value from it's original selling price!!!).

****** NOTICE: ******
You may assume that only correct data (positive and numeric) will be
entered. No data validation will be required.
Also, because of the rounding that occurs with C floating point
values, if the figures generated by your working C program
differ by 1 or 2 cents, this should not be considered significant
and can be ignored!

A few sample runs of the program should look like this:
\$ a.out
Used Car Estimator Program [UCEP]
Enter the current Year: 2010
Vehicle Make:
1 for Porsche,
2 for Chevrolet,
3 for Volkswagon,
4 for BMW,
5 for Audi,
6 for Honda,
7 for Ford,
8 for Mercedes
Enter choioce: 1
Enter the vehicle Year: 2003
Enter the vehicle's original selling price (M.S.R.P.): 70000.00
Enter the Kilometers driven: 12000

Automobile Information:
Make: Porsche
Year: 2003
Odometer: 12000
Depreciation: 7.01%

Selling Price: \$65090.00
Tax: \$ 8461.70
----------
Total: \$73551.70

\$ a.out
Used Car Estimator Program [UCEP]
Enter the current Year: 2010
Vehicle Make:
1 for Porsche,
2 for Chevrolet,
3 for Volkswagon,
4 for BMW,
5 for Audi,
6 for Honda,
7 for Ford,
8 for Mercedes
Enter choice: 3
Enter the vehicle Year: 2001
Enter the vehicle's original selling price (M.S.R.P.): 31500.00
Enter the Kilometers driven: 65267

Automobile Information:
Make: Volkswagon
Year: 2001
Odometer: 65267
Depreciation: 65.15%

Selling Price: \$10978.64
Tax: \$ 1427.22
----------
Total: \$12405.86

\$ a.out
Used Car Estimator Program [UCEP]
Enter the current Year: 2010
Vehicle Make:
1 for Porsche,
2 for Chevrolet,
3 for Volkswagon,
4 for BMW,
5 for Audi,
6 for Honda,
7 for Ford,
8 for Mercedes
Enter choice: 7
Enter the vehicle Year: 1965
Enter the vehicle's original selling price (M.S.R.P.): 1950.00
Enter the Miles driven: 5267

Automobile Information:
Make: Ford
Year: 1965
Odometer: 5267
Depreciation: -493.37%

Price: \$11570.78
Tax: \$ 1504.20
----------
Total: \$13074.98

This car is a CLASSIC!

\$ a.out
Used Car Estimator Program [UCEP]
Enter the current Year: 2010
Vehicle Make:
1 for Porsche
2 for Chevrolet
3 for Volkswagon
4 for BMW
5 for Audi
6 for Ford
7 for Mercedes
Enter choice: 2
Enter the vehicle Year: 1979
Enter the vehicle's original selling price (M.S.R.P.): 11500.00
Enter the Miles driven: 324689

I wouldn't buy this car if I were you!!!
--------------
Here's what I've managed so far:
Code:
#include <stdio.h>
#include <string.h>

int main () {
int cur_year, year_man, year_used, make_car, odo;
char make_carname[15];
double msrp, depreciation, dpy, dpk, depreciation_p, sell_price, gst, pst, tax, total;

printf("Used Car Estimator Program [UCEP]\nEnter the current Year: ");
scanf("%d", &cur_year);
printf("Vehicle Make:\n1 for Porsche,\n2 for Chevrolet,\n3 for Volkswagon,\n4 for BMW,\n5 for Audi,\n6 for Honda,\n7 for Ford,\n8 for Mercedes\nEnter choice: ");
scanf("%d", &make_car);
printf("Enter the vehicle Year: ");
scanf("%d", &year_man);
printf("Enter the vehicle's original selling price (M.S.R.P.): ");
scanf("%lf", &msrp);

switch (make_car) {
case 1:
strcpy(make_carname, "Porsche");
printf("Enter the Kilometers driven: ");
scanf("%d", &odo);
dpy = 650.00, dpk = 0.03;
break;

case 2:
strcpy(make_carname, "Chevrolet");
printf("Enter the Miles driven: ");
scanf("%d", &odo);
dpy = 1950.00, dpk = 0.11 * 0.62;
break;

case 3:
strcpy(make_carname, "Volkswagon");
printf("Enter the Kilometers driven: ");
scanf("%d", &odo);
dpy = 1700.00, dpk = 0.08;
break;

case 4:
strcpy(make_carname, "BMW");
printf("Enter the Kilometers driven: ");
scanf("%d", &odo);
dpy = 950.00, dpk = 0.05;
break;

case 5:
strcpy(make_carname, "Audi");
printf("Enter the Kilometers driven: ");
scanf("%d", &odo);
dpy = 1200.00, dpk = 0.06;
break;

case 6:
strcpy(make_carname, "Honda");
printf("Enter the Kilometers driven: ");
scanf("%d", &odo);
dpy = 1350.00, dpk = 0.07;
break;

case 7:
strcpy(make_carname, "Ford");
printf("Enter the Miles driven: ");
scanf("%d", &odo);
dpy = 2100.00, dpk = 0.04 * 0.62;
break;

case 8:
strcpy(make_carname, "Mercedes");
printf("Enter the Kilometers driven: ");
scanf("%d", &odo);
dpy = 875.00, dpk = 0.05;
break;

default:
printf("filler\n");
}

year_used = cur_year - year_man;
depreciation = /*(year_used * dpy) + */(odo * dpk);
sell_price = 10000 + (msrp - depreciation);
depreciation_p = depreciation / msrp * 100;
gst = sell_price / 100 * 5;
pst = sell_price / 100 * 8;
tax = gst + pst;
total = sell_price + tax;

if (make_car == 1 && total >= 0.00) {
printf("\nAutomobile Information:\nMake:        %s\nYear:        %d\n", make_carname, year_man);
printf("Odometer:      %d\n", odo);
printf("Depreciation:      %.2lf%%\n", depreciation_p);
printf("\nPrice:          \$%.2lf\n", sell_price);
printf("Tax:            \$%.2f\n", tax);
printf("                ---------\n");
printf("Total:          \$%.2lf\n", total);
}
else if (make_car == 2 && total >= 0.00) {
printf("\nAutomobile Information:\nMake:        %s\nYear:        %d\n", make_carname, year_man);
printf("Odometer:      %d\n", odo);
printf("Depreciation:      %.2lf%%\n", depreciation_p);
printf("\nPrice:          \$%.2lf\n", sell_price);
printf("Tax:            \$%.2f\n", tax);
printf("                ---------\n");
printf("Total:          \$%.2lf\n", total);
}
else if (make_car == 3 && total >= 0.00) {
printf("\nAutomobile Information:\nMake:        %s\nYear:        %d\n", make_carname, year_man);
printf("Odometer:      %d\n", odo);
printf("Depreciation:      %.2lf%%\n", depreciation_p);
printf("\nPrice:          \$%.2lf\n", sell_price);
printf("Tax:            \$%.2f\n", tax);
printf("                ---------\n");
printf("Total:          \$%.2lf\n", total);
}
else if (make_car == 4 && total >= 0.00) {
printf("\nAutomobile Information:\nMake:        %s\nYear:        %d\n", make_carname, year_man);
printf("Odometer:      %d\n", odo);
printf("Depreciation:      %.2lf%%\n", depreciation_p);
printf("\nPrice:          \$%.2lf\n", sell_price);
printf("Tax:            \$%.2f\n", tax);
printf("                ---------\n");
printf("Total:          \$%.2lf\n", total);
}
else if (make_car == 5 && total >= 0.00) {
printf("\nAutomobile Information:\nMake:        %s\nYear:        %d\n", make_carname, year_man);
printf("Odometer:      %d\n", odo);
printf("Depreciation:      %.2lf%%\n", depreciation_p);
printf("\nPrice:          \$%.2lf\n", sell_price);
printf("Tax:            \$%.2f\n", tax);
printf("                ---------\n");
printf("Total:          \$%.2lf\n", total);
}
else if (make_car == 6 && total >= 0.00) {
printf("\nAutomobile Information:\nMake:        %s\nYear:        %d\n", make_carname, year_man);
printf("Odometer:      %d\n", odo);
printf("Depreciation:      %.2lf%%\n", depreciation_p);
printf("\nPrice:          \$%.2lf\n", sell_price);
printf("Tax:            \$%.2f\n", tax);
printf("                ---------\n");
printf("Total:          \$%.2lf\n", total);
}
else if (make_car == 7 && total >= 0.00) {
printf("\nAutomobile Information:\nMake:        %s\nYear:        %d\n", make_carname, year_man);
printf("Odometer:      %d\n", odo);
printf("Depreciation:      %.2lf%%\n", depreciation_p);
printf("\nPrice:          \$%.2lf\n", sell_price);
printf("Tax:            \$%.2f\n", tax);
printf("                ---------\n");
printf("Total:          \$%.2lf\n", total);
}
else if (make_car == 8 && total >= 0.00) {
printf("\nAutomobile Information:\nMake:        %s\nYear:        %d\n", make_carname, year_man);
printf("Odometer:      %d\n", odo);
printf("Depreciation:      %.2lf%%\n", depreciation_p);
printf("\nPrice:          \$%.2lf\n", sell_price);
printf("Tax:            \$%.2f\n", tax);
printf("                ---------\n");
printf("Total:          \$%.2lf\n", total);
}
else {
printf("\nI wouldn't buy this car if I were you!!!\n");
}

printf("\n\nDEBUG MODE:\n\n year_used: %d\n make_car: %d\n make_carname: %s\n year_man: %d\n odo: %d\n depreciation: %.2lf\n depreciation_p: %.2lf%%\n sell_price: \$%.2lf\n tax: \$%.2lf\n total: \$%.2lf\n", year_used, make_car, make_carname, year_man, odo, depreciation, depreciation_p, sell_price, tax, total);
getchar ();
return 0;
}
Btw, only methods we've learned so far are :
if..elseif..s, switch, for loop...while.. loop... do while loop.. ...

so, can't really understand any other advanced methods....

Thanks for the help!

2. So what's wrong with your program? Don't waste our time here.

You figure out your assignment, and we will help you with the program - that's the deal. Be specific what you need help with. Our crystal ball is in the shop for repairs.

3. https://cs.senecac.on.ca/~ipc144/

Cheating and/or Plagiarism:

For a first offence you will be given a grade of 'F' for the test or assignment on which you cheated and it will be recorded in your personnel file. For a second offence the penalty will be a failure in the course and you will be expelled from the college.
Does this qualify?

4. no, since i'm not asking you guys to make the program work instead of me lol.

Just simply need to understand how to include the classic car check in the program without fking it up.. been trying by adding more ifs and even tried combining the switch and if statements into 1 single if statement, can't make it work yet

need a push to the right direction thats all.

5. wit hthe above program and after removing the comments..

Code:
Used Car Estimator Program [UCEP]
Enter the current Year: 2010
Vehicle Make:
1 for Porsche,
2 for Chevrolet,
3 for Volkswagon,
4 for BMW,
5 for Audi,
6 for Honda,
7 for Ford,
8 for Mercedes
Enter choioce: 1
Enter the vehicle Year: 2003
Enter the vehicle's original selling price (M.S.R.P.): 70000.00
Enter the Kilometers driven: 12000

Automobile Information:
Make: Porsche
Year: 2003
Odometer: 12000
Depreciation: 7.01%

Selling Price: \$65090.00
Tax: \$ 8461.70
----------
Total: \$73551.70

\$ a.out
Used Car Estimator Program [UCEP]
Enter the current Year: 2010
Vehicle Make:
1 for Porsche,
2 for Chevrolet,
3 for Volkswagon,
4 for BMW,
5 for Audi,
6 for Honda,
7 for Ford,
8 for Mercedes
Enter choice: 3
Enter the vehicle Year: 2001
Enter the vehicle's original selling price (M.S.R.P.): 31500.00
Enter the Kilometers driven: 65267

Automobile Information:
Make: Volkswagon
Year: 2001
Odometer: 65267
Depreciation: 65.15%

Selling Price: \$10978.64
Tax: \$ 1427.22
----------
Total: \$12405.86
will work just like in the examples given.. but i can't get the classic part done. that is my problem :|

6. I can't see why adding some
if ( make == 1 && year == 2 )
kind of logic would be difficult for you at this stage.

7. It's not, sorry i forgot to mention that this my warped version of the code I've been tryign to figure out for last 4-5 hrs @_@

this is a better code, below:

Code:
int main () {
int cur_year, year_man, year_used, make_car, odo;
char make_carname[15];
double msrp, depreciation, dpy, dpk, depreciation_p, sell_price, gst, pst, tax, total;

printf("Used Car Estimator Program [UCEP]\nEnter the current Year: ");
scanf("%d", &cur_year);
printf("Vehicle Make:\n1 for Porsche,\n2 for Chevrolet,\n3 for Volkswagon,\n4 for BMW,\n5 for Audi,\n6 for Honda,\n7 for Ford,\n8 for Mercedes\nEnter choice: ");
scanf("%d", &make_car);
printf("Enter the vehicle Year: ");
scanf("%d", &year_man);
printf("Enter the vehicle's original selling price (M.S.R.P.): ");
scanf("%lf", &msrp);

if (make_car == 1) {
strcpy(make_carname, "Porsche");
printf("Enter the Kilometers driven: ");
scanf("%d", &odo);
dpy = 650.00, dpk = 0.03;
year_used = cur_year - year_man;
depreciation = (year_used * dpy) + (odo * dpk);
sell_price = msrp - depreciation;
}
else if (make_car == 1 && year_man == 1948 || 1963 || 1965) {
strcpy(make_carname, "Porsche");
printf("Enter the Kilometers driven: ");
scanf("%d", &odo);
dpy = 650.00, dpk = 0.03;
year_used = cur_year - year_man;
depreciation = odo * dpk;
sell_price = msrp - depreciation;
sell_price = sell_price + 10000;
}
else if (make_car == 2) {
strcpy(make_carname, "Chevrolet");
printf("Enter the Miles driven: ");
scanf("%d", &odo);
dpy = 1950.00, dpk = 0.11 / 0.62;
year_used = cur_year - year_man;
depreciation = (year_used * dpy) + (odo * dpk);
sell_price = msrp - depreciation;
}
else if (make_car == 2 && year_man == 1955 || 1957) {
strcpy(make_carname, "Chevrolet");
printf("Enter the Miles driven: ");
scanf("%d", &odo);
dpy = 1950.00, dpk = 0.11 / 0.62;
year_used = cur_year - year_man;
depreciation = odo * dpk;
sell_price = msrp - depreciation;
sell_price = sell_price + 10000;
}
else if (make_car == 3) {
strcpy(make_carname, "Volkswagon");
printf("Enter the Kilometers driven: ");
scanf("%d", &odo);
dpy = 1700.00, dpk = 0.08;
year_used = cur_year - year_man;
depreciation = (year_used * dpy) + (odo * dpk);
sell_price = msrp - depreciation;
}
else if (make_car == 4) {
strcpy(make_carname, "BMW");
printf("Enter the Kilometers driven: ");
scanf("%d", &odo);
dpy = 950.00, dpk = 0.05;
year_used = cur_year - year_man;
depreciation = (year_used * dpy) + (odo * dpk);
sell_price = msrp - depreciation;
}
else if (make_car == 4 && year_man == 1955) {
strcpy(make_carname, "BMW");
printf("Enter the Kilometers driven: ");
scanf("%d", &odo);
dpy = 950.00, dpk = 0.05;
year_used = cur_year - year_man;
depreciation = odo * dpk;
sell_price = msrp - depreciation;
sell_price = sell_price + 10000;
}
else if (make_car == 5) {
strcpy(make_carname, "Audi");
printf("Enter the Kilometers driven: ");
scanf("%d", &odo);
dpy = 1200.00, dpk = 0.06;
year_used = cur_year - year_man;
depreciation = (year_used * dpy) + (odo * dpk);
sell_price = msrp - depreciation;
}
else if (make_car == 6) {
strcpy(make_carname, "Honda");
printf("Enter the Kilometers driven: ");
scanf("%d", &odo);
dpy = 1350.00, dpk = 0.07;
year_used = cur_year - year_man;
depreciation = (year_used * dpy) + (odo * dpk);
sell_price = msrp - depreciation;
}
else if (make_car == 7) {
strcpy(make_carname, "Ford");
printf("Enter the Miles driven: ");
scanf("%d", &odo);
dpy = 2100.00, dpk = 0.09 / 0.62;
year_used = cur_year - year_man;
depreciation = (year_used * dpy) + (odo * dpk);
sell_price = msrp - depreciation;
}
else if (make_car == 7 && year_man == 1931 || 1957 || 1964 || 1965) {
strcpy(make_carname, "Ford");
printf("Enter the Miles driven: ");
scanf("%d", &odo);
dpy = 2100.00, dpk = 0.09 / 0.62;
year_used = cur_year - year_man;
depreciation = odo * dpk;
sell_price = msrp - depreciation;
sell_price = sell_price + 10000;
}
else if (make_car == 8) {
strcpy(make_carname, "Mercedes");
printf("Enter the Kilometers driven: ");
scanf("%d", &odo);
dpy = 875.00, dpk = 0.05;
year_used = cur_year - year_man;
depreciation = (year_used * dpy) + (odo * dpk);
sell_price = msrp - depreciation;
}

depreciation_p = depreciation / msrp * 100;
gst = sell_price / 100 * 5;
pst = sell_price / 100 * 8;
tax = gst + pst;
total = sell_price + tax;

if (make_car >= 1, make_car <= 8 && total >= 0.00) {
printf("\nAutomobile Information:\nMake:		%s\nYear:		%d\n",
make_carname, year_man);
printf("Odometer:  	%d\n", odo);
printf("Depreciation:  	%.2lf%%\n", depreciation_p);
printf("\nPrice:          \$%.2lf\n", sell_price);
printf("Tax:            \$%.2f\n", tax);
printf("                ---------\n");
printf("Total:          \$%.2lf\n", total);
}
else if (make_car == 1 && year_man == 1948 || 1963 || 1965) {
printf("\nAutomobile Information:\nMake:		%s\nYear:		%d\n",
make_carname, year_man);
printf("Odometer:  	%d\n", odo);
printf("Depreciation:  	%.2lf%%\n", depreciation_p);
printf("\nPrice:          \$%.2lf\n", sell_price);
printf("Tax:            \$%.2f\n", tax);
printf("                ---------\n");
printf("Total:          \$%.2lf\n", total);
printf("\nThis car is a CLASSIC!\n");
}
else if (make_car == 2 && year_man == 1955 || 1957) {
printf("\nAutomobile Information:\nMake:		%s\nYear:		%d\n",
make_carname, year_man);
printf("Odometer:  	%d\n", odo);
printf("Depreciation:  	%.2lf%%\n", depreciation_p);
printf("\nPrice:          \$%.2lf\n", sell_price);
printf("Tax:            \$%.2f\n", tax);
printf("                ---------\n");
printf("Total:          \$%.2lf\n", total);
printf("\nThis car is a CLASSIC!\n");
}
else if (make_car == 4 && year_man == 1955) {
printf("\nAutomobile Information:\nMake:		%s\nYear:		%d\n",
make_carname, year_man);
printf("Odometer:  	%d\n", odo);
printf("Depreciation:  	%.2lf%%\n", depreciation_p);
printf("\nPrice:          \$%.2lf\n", sell_price);
printf("Tax:            \$%.2f\n", tax);
printf("                ---------\n");
printf("Total:          \$%.2lf\n", total);
printf("\nThis car is a CLASSIC!\n");
}
else if (make_car == 7 && year_man == 1931 || 1957 || 1964 || 1965) {
printf("\nAutomobile Information:\nMake:		%s\nYear:		%d\n",
make_carname, year_man);
printf("Odometer:  	%d\n", odo);
printf("Depreciation:  	%.2lf%%\n", depreciation_p);
printf("\nPrice:          \$%.2lf\n", sell_price);
printf("Tax:            \$%.2f\n", tax);
printf("                ---------\n");
printf("Total:          \$%.2lf\n", total);
printf("\nThis car is a CLASSIC!\n");
}
else {
printf("\nI wouldn't buy this car if I were you!!!\n");
}
printf("\n\nDEBUG MODE:\n\n year_used: %d\n make_car: %d\n make_carname: %s\n year_man: %d\n odo: %d\n depreciation: %.2lf\n depreciation_p: %.2lf%%\n sell_price: \$%.2lf\n tax: \$%.2lf\n total: \$%.2lf\n",
year_used, make_car, make_carname, year_man, odo, depreciation, depreciation_p, sell_price, tax, total);
getchar ();
return 0;
}
All that does is:

1) able to calculate the stuff for make_car 1-8 without taking classic car logic into the equation
2) able to print to user if it's classic car.

i'm working on trying to figure out what the equation for classic car config is :S

thanks for the help!

8. i rewrote the program over 10 times so far heh.
maybe it's cos' i've been trying to figure it out for so long that my head's not working haha.. so i guess ill get to it in the morning again!

any help in the right direction is appreciated~~!!

9. Instead of two else if() statements for every make of car that could be a classic, I would use just one:

This is your current code for BMW:
Code:
else if (make_car == 4) {
strcpy(make_carname, "BMW");
printf("Enter the Kilometers driven: ");
scanf("%d", &odo);
dpy = 950.00, dpk = 0.05;
year_used = cur_year - year_man;
depreciation = (year_used * dpy) + (odo * dpk);
sell_price = msrp - depreciation;
}
else if (make_car == 4 && year_man == 1955) {
strcpy(make_carname, "BMW");
printf("Enter the Kilometers driven: ");
scanf("%d", &odo);
dpy = 950.00, dpk = 0.05;
year_used = cur_year - year_man;
depreciation = odo * dpk;
sell_price = msrp - depreciation;
sell_price = sell_price + 10000;
}

// and I would put the logic into a more unified format:

else if (make_car == 4) {
strcpy(make_carname, "BMW");
printf("Enter the Kilometers driven: ");
scanf("%d", &odo);
if(year_make = 1955)  {
classic = 1;     //a flag. classic = 0 means no classic, = 1 means it is
put your code to handle classic cars in here.

dpy = 950.00, dpk = 0.05;
year_used = cur_year - year_man;
depreciation = odo * dpk;
sell_price = msrp + 10000;

}
else {   //code for non classic models in here

dpy = 950.00, dpk = 0.05;
year_used = cur_year - year_man;
depreciation = (year_used * dpy) + (odo * dpk);
sell_price = msrp - depreciation;
}

/*  and remove all this. Even for a student, a calculation shouldn't have to be
done twice, as is the case here. Because all the BMW's entered will be
calculated in the above example, and then all the classic BMW's will be
calculated all over, in this block of code. :(
*/
else if (make_car == 4 && year_man == 1955) {
strcpy(make_carname, "BMW");
printf("Enter the Kilometers driven: ");
scanf("%d", &odo);
}
Arrange it to your advantage, and use the classic car flag, when you can, to reduce code redundancy and improve clarity.

If you work out the process, on paper first, I don't believe you'll have a lot of trouble. Sometimes just sitting down and entering code is the worst way to start a program - especially for a beginner.

10. True, i did think all those calculations were redundant, but just didn't know how to trim it down haha.

thanks for the help! i can see the light at the end of the tunnel again

Popular pages Recent additions