/*Taking input from user to calculate the cost of a travel plan using the number of travelers/ number of stops/ cost of each stop giving both the half cost of a trip and its full price*/ int calculate( int total); #include <stdio.h> int main(void) { float customer, stops, response, cost, i, stop, total, halfcost, totaltrip; i=0; printf("Welcome to Airline express.\n"); printf("Would you like to calculate the cost of a trip?"); scanf("%f", &response); while ( response != 0 ) { printf("Please enter how many customer will be traveling. Children under 12 are counted as .5:"); scanf("%f", &customer); if (customer < 0) customer = 3; printf("Please enter how many stops there are:"); scanf("%f", &stop); while (i<stop) { printf("Please enter cost of the next stop:"); scanf("%f", &cost); if (cost < 0) cost = 100; total +=cost; i++; } halfcost = calculate(total); printf("Half cost is: %f", halfcost); totaltrip = total * customer; printf("Total cost for trip is: %f\n", totaltrip); printf("Would you like to calculate another trip?"); scanf("%f", &response); } return 0; } int calculate( int total) { return total/2; } I'm having issues with the inputs, I'm trying to make the loop run as the user request another calculations. But when ever it re runs another test it keeps the input of the previous test is there a way to reset the variables to 0? Ive tried assign all of the variable inside and outside of the loop but I'm kinda lost on what to go from here.
floatisn't an appropriate data type for things that are countable (like the number of stops).totalis one of the few variables that probably should accept fractional values, and you pass it in anintparameter.total(even the first time around); it is not guaranteed to be 0 before you start addingcosts to it.responseshould also be a char... just a Y/y or N/n is an intuitive input.