Ive spent almost 4 hours messing with this code trying to figure out whats wrong...to no avail.
I keep getting zero as the total in the displayTripCost function at the bottom, i dont know if i messed up the pointers or what when i called by reference.... Please help!!!
//Toni-Ann Mighty
//October 20, 2013
//Call By Reference
#include <stdio.h>
#include <stdlib.h>
#define pause system("pause")
#define cls system("cls")
//Lets Prototype
void getUserInput(int *millage, int *price, int *mpg);
int getChoice();
void displayMenu();
void updateCurrentMillage(int *millage);
void updatePricePerGallon(int *price);
void displayTripCost(int,int,int);
main(){
int choice=0,currentMillage=0, MPG=0;
int pricePerGallonOfGas=0;
getUserInput(¤tMillage, &pricePerGallonOfGas, &MPG);
do {
choice = getChoice();
switch (choice) {
case 1:
updateCurrentMillage(¤tMillage);
break;
case 2:
updatePricePerGallon(&pricePerGallonOfGas);
break;
case 3:
displayTripCost(currentMillage, pricePerGallonOfGas, MPG);
break;
} //end switch
} while(choice!=4);
}//end main
void getUserInput(int *millage, int *price, int *mpg){
printf("Please enter your current millage\nin other words how many miles have you driven?: \n");
scanf_s("%i",millage);
printf("\nPlease enter the price per gallon of gas: \n");
scanf_s("%i", price);
printf("\nPlease enter the MPG of your car: \n");
scanf_s("%i",mpg);
printf("Thank You\n");
pause;
}//end getUserInput
int getChoice(){
int result;
do {
displayMenu();
scanf_s("%i", &result);
if(result < 1 || result > 4){
printf("Error! I said to enter between 1-4!\n");
pause;
}//end if
} while (result < 1 || result > 4);
return result;
} //end function getChoice
void displayMenu(){
cls;
printf("Main Menu\n\n");
printf("1.Update Your Current Millage\n");
printf("2.Update Your Total Spent of Gas\n");
printf("3.View The Total Cost of your trip\n");
printf("4.QUIT\n\n");
printf("Please Make a selection..");
}//end display menu
void updateCurrentMillage(int *millage){
printf("How miles have you driven in total now?\n\n ");
scanf_s("%i",millage);
printf("\nYour Milliage has been updated\n");
pause;
}//end updateCurrentMillage
void updatePricePerGallon(int *price){
printf("How much does a gallon of gas cost now?\n\n");
scanf_s("%i",price);
printf("\nThe price of gas has been updated\n");
pause;
}//end updatePricePerGallon
void displayTripCost(int millage, int cost, int mpg){
int math = cost/mpg, total = millage * math;
printf("The cost of your trip is %i \n",total);
pause;
}//end displayTripCost