![]() |
| | #1 | |
| Registered User Join Date: Feb 2010 Location: Toronto
Posts: 6
| c program help :> Here's the question: Quote:
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;
}
if..elseif..s, switch, for loop...while.. loop... do while loop.. ... so, can't really understand any other advanced methods.... Thanks for the help! | |
| n2134 is offline | |
| | #2 |
| Registered User Join Date: Sep 2006
Posts: 3,720
| 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. |
| Adak is offline | |
| | #3 | |
| a_capitalist_story Join Date: Dec 2007
Posts: 993
| https://cs.senecac.on.ca/~ipc144/ Quote:
| |
| rags_to_riches is offline | |
| | #4 |
| Registered User Join Date: Feb 2010 Location: Toronto
Posts: 6
| 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. Last edited by n2134; 02-05-2010 at 10:16 PM. |
| n2134 is offline | |
| | #5 |
| Registered User Join Date: Feb 2010 Location: Toronto
Posts: 6
| 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 |
| n2134 is offline | |
| | #6 |
| and the hat of Destiny Join Date: Aug 2001 Location: The edge of the known universe
Posts: 22,495
| I can't see why adding some if ( make == 1 && year == 2 ) kind of logic would be difficult for you at this stage. |
| Salem is offline | |
| | #7 |
| Registered User Join Date: Feb 2010 Location: Toronto
Posts: 6
| 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;
}
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! |
| n2134 is offline | |
| | #8 |
| Registered User Join Date: Feb 2010 Location: Toronto
Posts: 6
| 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~~!! |
| n2134 is offline | |
| | #9 |
| Registered User Join Date: Sep 2006
Posts: 3,720
| 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);
}
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. |
| Adak is offline | |
| | #10 |
| Registered User Join Date: Feb 2010 Location: Toronto
Posts: 6
| 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 |
| n2134 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using variables in system() | Afro | C Programming | 8 | 07-03-2007 12:27 PM |
| BOOKKEEPING PROGRAM, need help! | yabud | C Programming | 3 | 11-16-2006 11:17 PM |
| Can someome help me with a program please? | WinterInChicago | C++ Programming | 3 | 09-21-2006 10:58 PM |
| My program, anyhelp | @licomb | C Programming | 14 | 08-14-2001 10:04 PM |