I am submitting my assignment for review by pro's to see if you think this code is clean and follows standard programming. The criteria of my assignment are met with my code, but I know someone would have a good suggestion for cleaning it up a bit.
Assignment:
Prompt for clerck to enter current prices for products.
Then display those product prices back.
Use a customer checkout function to prompt the customer for how much of each
item he or she would like to purchase.
If the total is more than $50, a 5% discount is applied.
Prompt user to enter the amount of money the customer has to spend.
Compare that with the total of the purchase and display change or amount due.
My Code
#include<time.h>
#include <stdio.h>
int main(void) //Beginning of program
{
time_t timer;
float flbGrapes1;
float flbPears2;
float flbBellpeppers3;
float flbNectarines4;
float flbPotatoes5;
float fMoney;
float fMoney2;
float ftotLbs1;
float ftotLbs2;
float ftotLbs3;
float ftotLbs4;
float ftotLbs5;
float fTotGrapes1;
float fTotPears2;
float fTotBellpeppers3;
float fTotNectarines4;
float fTotPotatoes5;
float ftotPurch;
float fdisc;
float ftotDollar;
//initialize variables
flbGrapes1 = 0.00;
flbPears2 = 0.00;
flbBellpeppers3 = 0.00;
flbNectarines4 = 0.00;
flbPotatoes5 = 0.00;
fMoney = 0.00;
fMoney2 = 0.00;
ftotLbs1 = 0.00;
ftotLbs2 = 0.00;
ftotLbs3 = 0.00;
ftotLbs4 = 0.00;
ftotLbs5 = 0.00;
timer=time(NULL);
ftotDollar = (flbGrapes1 * ftotLbs1) + (flbPears2 * ftotLbs2) + (flbBellpeppers3 * ftotLbs3) + (flbNectarines4 * ftotLbs4) + (flbPotatoes5 * ftotLbs5);
fdisc = (ftotPurch * .05);
//Greeting and time
printf("Welcome to Reggie's Friendly Neighborhood Grocery Store!\n");
printf("\n");
printf("The current time is %s\n",asctime(localtime(&t
imer)));
printf("\n");
printf("\n");
//Prompt user to enter price per pound
printf("Please enter the price per pound for your Grapes: $");
scanf("%f", &flbGrapes1);
printf("\n");
printf("Please enter the price per pound for your Pears: $");
scanf("%f", &flbPears2);
printf("\n");
printf("Please enter the price per pound for your Bell peppers: $");
scanf("%f", &flbBellpeppers3);
printf("\n");
printf("Please enter the price per pound for your Nectarines: $");
scanf("%f", &flbNectarines4);
printf("\n");
printf("Please enter the price per pound for your Potatoes: $");
scanf("%f", &flbPotatoes5);
printf("\n");
printf("\n");
//Display price per pound entered
printf("You have entered the following:\n");
printf("\n");
printf("$%.2f a pound for grapes.\n", flbGrapes1);
printf("\n");
printf("$%.2f a pound for pears.\n", flbPears2);
printf("\n");
printf("$%.2f a pound for bell peppers.\n", flbBellpeppers3);
printf("\n");
printf("$%.2f a pound for nectarines.\n", flbNectarines4);
printf("\n");
printf("$%.2f a pound for potatoes.\n", flbPotatoes5);
printf("\n");
printf("\n");
//Ask for the total pounds
printf("How many pounds of grapes would you like to purchase?\n", ftotLbs1);
printf("\n");
scanf("%f", &ftotLbs1);
printf("\n");
printf("The total amount for the grapes is $%.2f: \n", flbGrapes1 * ftotLbs1);
printf("\n");
printf("\n");
printf("How many pounds of pears would you like to purchase?\n", ftotLbs2);
printf("\n");
scanf("%f", &ftotLbs2);
printf("\n");
printf("The total amount for the pears is $%.2f: \n", flbPears2 * ftotLbs2);
printf("\n");
printf("\n");
printf("How many pounds of bell peppers would you like to purchase?\n", ftotLbs3);
printf("\n");
scanf("%f", &ftotLbs3);
printf("\n");
printf("The total amount for the bell peppers is $%.2f: \n", flbBellpeppers3 * ftotLbs3);
printf("\n");
printf("\n");
printf("How many pounds of nectarines would you like to purchase?\n", flbNectarines4 * ftotLbs4);
printf("\n");
scanf("%f", &ftotLbs4);
printf("\n");
printf("The total amount for the nectarines is $%.2f: \n", flbNectarines4 * ftotLbs4);
printf("\n");
printf("\n");
printf("How many pounds of potatoes would you like to purchase?\n", flbPotatoes5 * ftotLbs5);
printf("\n");
scanf("%f", &ftotLbs5);
printf("\n");
printf("The total amount for the potatoes is $%.2f: \n", flbPotatoes5 * ftotLbs5);
printf("\n");
printf("\n");
ftotDollar = (flbGrapes1 * ftotLbs1) + (flbPears2 * ftotLbs2) + (flbBellpeppers3 * ftotLbs3) + (flbNectarines4 * ftotLbs4) + (flbPotatoes5 * ftotLbs5);
//Total dollar amount of all products entered
printf("The total of these products is $%.2f \n", ftotDollar);
printf("\n");
fdisc = (ftotDollar * .05);
ftotPurch = (ftotDollar - fdisc);
ftotDollar = (flbGrapes1 * ftotLbs1) + (flbPears2 * ftotLbs2) + (flbBellpeppers3 * ftotLbs3) + (flbNectarines4 * ftotLbs4) + (flbPotatoes5 * ftotLbs5);
//If total amount is over $50
{
if (ftotDollar > 50.00)
printf("You will receive a 5 percent discount, which totals: $%.2f \n", fdisc);
printf("\n");
if (ftotDollar > 50.00)
printf("The total amount of your purchase is $%.2f \n", ftotPurch);
printf("\n");
}
printf("Enter the amount of money that you will be spending: $");
scanf("%f", &fMoney);
printf("\n");
printf("\n");
{
if (fMoney < ftotDollar)
printf("Amount entered is not enough for purchase, please input a larger amount: $");
scanf("%f", &fMoney);
printf("\n");
if (fMoney > ftotDollar)
printf("Your change is $%.2f \n", fMoney-ftotDollar);
else
printf("Your change is $%.2f \n", fMoney-ftotPurch);
printf("\n");
printf("Thank you for shopping at Reggie's! Have a good day and please visit us again!");
}
{
if (fMoney < ftotPurch)
printf("Amount entered is not enough for purchase, please input a larger amount: $");
scanf("%f", &fMoney);
printf("\n");
if (fMoney > ftotPurch)
printf("Your change is $%.2f \n", fMoney-ftotPurch);
printf("\n");
}
printf("Thank you for shopping at Reggie's! Have a good day and please visit us again!");
getchar();
return 0;
}