When I'm using functions in code do I use them to replace my if
statements, I guess I'm just not certain where to put them.
I am supposed to change the code in this and add functions.
Code:#include <stdio.h> #define REGFEE 35.00 #define SURCHG 15.00 #define CITYV 20.00 main() { void GetCtype(); void GetVtype(); int vtype, ctype, custcount = 0; char answer; double totfee, totcustchg = 0.0; do { int GetCtype(); printf("\nPlease enter a 1 for Luxury Car, or 2 for Other Car: "); scanf("%d", &vtype); if (!(vtype ==1 || vtype == 2)) { printf("\nInvalid Data Entered: "); } else { int GetVtype(); printf("\nPlease enter a 1 for City Vehicle, or 2 for Non-City Vehicle: "); scanf("%d", &ctype); if (!(ctype ==1 || ctype ==2)) { printf("\nInvalid Data Entered: "); } else { if ((vtype == 1) && (ctype ==1)) { totfee = REGFEE + SURCHG + CITYV; } else { totfee = REGFEE + SURCHG; if ((vtype ==2) && (ctype ==2)) { totfee = REGFEE; } else { totfee = REGFEE + CITYV; } } } } printf("\nTotal Fee %.2f\n", totfee); //Accumulators ++custcount; totcustchg += totfee; //Prompt for another car printf("\nDo you want to process another vehicle?(y/n): "); getchar(); answer = getchar(); } while (( answer == 'y') || (answer == 'Y') ); //Display summary info printf("\nTotal number of cars processed: %d\n", custcount); printf("\nTotal registration fee for all automobiles: $%.2lf\n", totcustchg); }




Reply With Quote