I am new at this but I think I may have it. This is the assignment:

The program should ask for the Customers First Name and Last Name (Use Initials only for now)

-Use 2 different variables, one for the first name and one for the last

The program should ask for the prices of 5 different items

-Use 5 different input statements and 5 different variables

The program should add the 5 products together giving the subtotal price.

Find the Tax by multiplying the Subtotal by a Constant called TaxRate

For the Total, add the Tax to the subtotal

Output the First initial, a period and space, last initial, a period and space, a message to the user and the total

Example:

``````Please enter First initial

SubTotal = Item1 + Item2 + Item3 + Item4 + Item5

Tax = SubTotal * TaxRate

Total = SubTotal + Tax

OutPut=

B. S.

Here is my code:

``````include <stdio.h>

#define TaxRate 10.0f

/* global variable*/
char firstname[20];
char lastname[20];
float Tax;
float st;
float Item1,Item2,Item3,Item4,Item5;
float total;

/*functions protypes*/
void enterItemPrice(void);
float subTotal(void);
float calculatetax(void);
float totalprice(void);
void output(void);

int main(void)
{

enterItemPrice();
st = subTotal();
calculatetax();
totalprice();
output();

return 0;
}

{
scanf("%s", firstname);
scanf("%s", lastname);
}

void enterItemPrice(void)
{
printf("\nEnter price of item1:");
scanf("%f", &Item1);

printf("\nEnter price of item2:");
scanf("%f", &Item2);

printf("\nEnter price of item3:");
scanf("%f", &Item3);

printf("\nEnter price of item4:");
scanf("%f", &Item4);

printf("\nEnter price of item5:");
scanf("%f", &Item5);

}

float subTotal(void)
{
float localst;
localst = Item1 + Item2 + Item3 + Item4;
return localst;

}

float calculatetax(void)
{
Tax = st * TaxRate;
}

float totalprice(void)
{
total= Tax + st;
}

void output(void)
{
printf("the costumer's first name is %s", firstname);
printf("\nthe costumer's last name is %s", lastname);
printf("\nThe price of the first item is %f", Item1);
printf("\nThe price of the first item is %f", Item2);
printf("\nThe price of the first item is %f", Item3);
printf("\nThe price of the first item is %f", Item4);
printf("\nThe price of the first item is %f", Item5);
printf("\nthe subtotal is %f", st);
printf("\nthe taxable price is %f", Tax);
printf("\n the total price is %f", total);

}``````
4
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by secretunfold

What is the question? Use code tags the next time.

Ok in subtotal function you are not adding the value of the fifth item.
Now if you can, try to avoid globals, use them only if you must . Read this link for string input (don't get me wrong your prog is working with scanf but read the link).
PS: I hope that you are not taxed like this :) .

``````include <stdio.h>

#define TaxRate 10.0f

/* global variable*/
char firstname[20];
char lastname[20];
float Tax;
float st;
float Item1,Item2,Item3,Item4,Item5;
float total;

/*functions protypes*/
void enterItemPrice(void);
float subTotal(void);
float calculatetax(void);
float totalprice(void);
void output(void);

int main(void)
{

enterItemPrice();
st = subTotal();
calculatetax();
totalprice();
output();

return 0;
}

{
scanf("%s", firstname);
scanf("%s", lastname);
}

void enterItemPrice(void)
{
printf("\nEnter price of item1:");
scanf("%f", &Item1);

printf("\nEnter price of item2:");
scanf("%f", &Item2);

printf("\nEnter price of item3:");
scanf("%f", &Item3);

printf("\nEnter price of item4:");
scanf("%f", &Item4);

printf("\nEnter price of item5:");
scanf("%f", &Item5);

}

float subTotal(void)
{
float localst;
localst = Item1 + Item2 + Item3 + Item4;
return localst;

}

float calculatetax(void)
{
Tax = st * TaxRate;
}

float totalprice(void)
{
total= Tax + st;
}

void output(void)
{
printf("the costumer's first name is %s", firstname);
printf("\nthe costumer's last name is %s", lastname);
printf("\nThe price of the first item is %f", Item1);
printf("\nThe price of the first item is %f", Item2);
printf("\nThe price of the first item is %f", Item3);
printf("\nThe price of the first item is %f", Item4);
printf("\nThe price of the first item is %f", Item5);
printf("\nthe subtotal is %f", st);
printf("\nthe taxable price is %f", Tax);
printf("\n the total price is %f", total);

}``````
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.