I'm having trouble passing differing values between multiple functions. That is, i'm trying to have two functions take user inputs, and then have both of those inputs passed to a third function that calculates those inputs added together. Afterwards, it passes that total on to another function that calculates the true total. Finally, after that, the last function displays the final number. I can't seem to figure out how to make multiple functions pass though.
# include <stdio.h>
# include <stdlib.h>
int carLength(int userInput) //Length
{
int length = 0;
do
{
printf("\nPlease input the length of the area being carpeted:");
scanf("%d", &userInput);
} while (length = 0);
length = userInput; //Essentially using this to store user input so i can
use it later.
return length;
}
int carWidth(int userInput) //Width
{
int width = 0;
do
{
printf("\nPlease input the width of the area being carpeted:");
scanf("%d", &userInput);
} while (width = 0);
width = userInput; //Same as width
return width;
}
int carCalculate(int cost) //cost
{
int width = userInput;
int cost = (width * length) * 20;
return cost;
}
float cardiscount(float discount) //discount
{
float discount = cost - (cost * .1);
return discount;
}
float displaydisc(float discount) //discount
{
printf("\nThe total cost is: %f\n", discount);
return discount;
}
int main()
{
int length = 0;
int width = 0;
int cost = 0;
int discount = 0;
do {
length = carLength;
} while (length == 0);
do {
width = carWidth;
} while (carWidth == 0);
do {
cost = carCalculate;
} while (cost == 0);
do {
discount = cardiscount;
} while (discount == 0);
do {
displaydisc;
} while (discount > 0);
printf("\n Thank you for using this program!");
system("pause");
}