|
Would Anyone Like to do This?
I am having trouble doing the following C project...if anyone is interested in helping me fulfil the following conditions for the code below, i would be willing to compensate them for their time. here are the specifications for the project. The code below is the code that is being modified. it compiles and runs. PM me if you would like to help. Thanks, bradc0101.
Modify Project 3 in the following way:
The very first thing and only once in the program: prompt the user for a SEED for the random number generator.
Design a looping structure that will allow the user to create multiple bills; in other words, keep running the program until I let you know I'm done.
Use a random number to get the discount instead of prompting the user for this value. The discount should range from 0 to 50.
Prompt the user for the Length, Width, and Price.
Test your input for validity: the Length should be a positive number; it should also be at least 2 feet and no more than 50. If I enter a number less than 2 or larger than 50, prompt me to reenter the length until the value is within the valid range.
Test your input for validity: the Width should be a positive number; it should also be at least 2 feet and no more than 30. If I enter a number less than 2 or larger than 50, prompt me to reenter the width until the value is within the valid range.
Test your input for validity: the Price should be a positive number; it should also be at least $1.00 and no more than $20.00. If I enter a number less than 1.00 or larger than 20.00, prompt me to reenter the price until the value is within the valid range.
Use a menu allow the use to see the specific charges they want to see, not the entire bill.
Sample menu:
**************************************************
* SELECT 1 for the AREA *
* SELECT 2 for the CARPET COST *
* SELECT 3 for the LABOR CHARGE *
* SELECT 4 for the INSTALLED PRICE *
* SELECT 5 for the DISCOUNT AMOUNT *
* SELECT 6 for the TAX *
* SELECT 7 for the TOTAL *
* SELECT 9 for another bill *
* SELECT 0 to quit *
**************************************************
Display the requested output until the user wants to go back to the menu and select something else. When the user selects 9 to create another bill, you must return back to the beginning of the program and prompt the user for a new Length, Width, and Cost.
When the user selects 0 to quit, gracefully exit the program.
You will use functions and addresses as in the original assignment, but you may combine several functions that may seem related to you. Your main should not be cluttered and full of activity. It should be a driver (like a supervisor) calling the other functions in the proper order and sending the values or addresses those functions need to get their jobs done.
#include <stdio.h>
#define Sales_Tax 8.5
#define Labor_Cost .35
//Function Definitions
void readData(int* Length, int* Width, float* Discount, float* CostSqFt);
void calcValues(int* Length, int* Width, float* Discount, float* CostSqFt, float* Labor, float* CarpetCost, float* LaborCha$
float *InstP, float *SubTot, float* Tax, float* Total, float* DiscountCalc, int* SqFt);
void calcInstPrice(int *SqFt, int Length, int Width, float *CarpetCost, float CostSqFt, float *LaborCharge, float *InstP);
void calcSub(float *DiscountCalc, float InstP, float *SubTot, float Discount);
void calcTaxTot(float *Tax, float SubTot, float *Total);
void printResults(int* Length, int* Width, float* Discount, float* CostSqFt, float* Labor, float* CarpetCost, float* LaborC$
float *InstP, float *SubTot, float* Tax, float* Total, float* DiscountCalc, int* SqFt);
void printCharges(float CostSqFt, float CarpetCost, float LaborCharge, float InstP, float Discount, float DiscountCalc, flo$
float Tax, float Total);
void printMeasurements(int Length, int Width, int SqFt);
int main(void)
{
//Constants
// Variable Decleration
int Length;
int Width;
float Discount;
float CostSqFt,Labor,CarpetCost,LaborCharge,InstP,SubTot,Tax,Total,DiscountCalc;
int SqFt;
//Call function to read in data
readData(&Length, &Width, &Discount, &CostSqFt);
//Call function that calculates all values
calcValues(&Length, &Width, &Discount, &CostSqFt, &Labor, &CarpetCost, &LaborCharge, &InstP, &SubTot, &Tax, &Total,
&DiscountCalc, &SqFt);
//Call print function
printResults(&Length, &Width, &Discount, &CostSqFt, &Labor, &CarpetCost, &LaborCharge, &InstP, &SubTot, &Tax, &Total,
&DiscountCalc, &SqFt);
}
//================================================================================
/* readData function: Successfully reads in all the data and passes it in the calling functions variables */
void readData(int* Length, int* Width, float* Discount, float* CostSqFt)
{
// Prompt User
printf("\nLength Of Room (feet)? ");
scanf("%d", Length);
printf("Width Of Room (feet)? ");
scanf("%d", Width);
printf("Customer Discount (percent)? ");
scanf("%f", Discount);
printf("Cost per Square Foot (XXX.XX)? ");
scanf("%f", CostSqFt);
}
//===============================================================================
void calcValues(int* Length, int* Width, float* Discount, float* CostSqFt, float* Labor, float* CarpetCost, float* LaborCha$
float *InstP, float *SubTot, float* Tax, float* Total, float* DiscountCalc, int* SqFt)
{
//Call first subfunction
calcInstPrice(SqFt, *Length, *Width, CarpetCost, *CostSqFt, LaborCharge, InstP);
//Call second subfunction
calcSub(DiscountCalc, *InstP, SubTot, *Discount);
//Call third subfunction
calcTaxTot(Tax, *SubTot, Total);
}
//First Subfinction
void calcInstPrice(int *SqFt, int Length, int Width, float *CarpetCost, float CostSqFt, float *LaborCharge, float *InstP)
{
*SqFt=(Length)*(Width);
*CarpetCost=(CostSqFt) * (*SqFt);
*LaborCharge=((Labor_Cost))*(*SqFt);
*InstP=*LaborCharge+*CarpetCost;
//Test to make sure data was passed correctly
//printf("L: %d, W: %d, CostSqFt: %f, SqFt: %d, LaborCharge: %f", Length, Width, CostSqFt, SqFt, LaborCharge);
}
//Second Subfunction
void calcSub(float *DiscountCalc, float InstP, float *SubTot, float Discount)
{
*DiscountCalc=((Discount)/100.0)*(InstP);
*SubTot=InstP-Discount;
//printf("1: %f, 2: %f, 3: %f 4: %f", DiscountCalc, InstP, SubTot, Discount);
}
//Third Subfunction
void calcTaxTot(float *Tax, float SubTot, float *Total)
{
*Tax=SubTot*((Sales_Tax)/100);
*Total=SubTot+*Tax;
}
//==========================================================================================
void printResults(int* Length, int* Width, float* Discount, float* CostSqFt, float* Labor, float* CarpetCost, float* LaborC$
float *InstP, float *SubTot, float* Tax, float* Total, float* DiscountCalc, int* SqFt)
{
//Call function to print Measurements
printMeasurements(*Length, *Width, *SqFt);
//Call function to print Charges
printCharges(*CostSqFt, *CarpetCost, *LaborCharge, *InstP, *Discount, *DiscountCalc, *SubTot, *Tax, *Total);
}
//=============================Measurements=============================================================
//This prints the Specified Measurements
void printMeasurements(int Length, int Width, int SqFt)
{
// Results
printf("\n Measurements\n\n");
printf("Length %d ft\n", Length);
printf("Width %d ft\n", Width);
printf("Area %d sq ft\n\n", SqFt);
}
//============================Charges=============================================================
//Prints the final data
void printCharges(float CostSqFt, float CarpetCost, float LaborCharge, float InstP, float Discount, float DiscountCalc, flo$
float Tax, float Total)
{
printf(" Charges\n\n");
printf("Description Cost/SqFt Charge\n");
printf("----------- --------- -----------\n");
printf("Carpet %6.2f $%6.2f\n",CostSqFt,CarpetCost);
printf("Labor %6.2f %6.2f\n",Labor_Cost,LaborCharge);
printf(" -----------\n");
printf("Installed Price $6%.2f\n",InstP);
printf("Discount %4.2f %6.2f\n",Discount,DiscountCalc);
printf(" -----------\n");
printf("Subtotal $%6.2f\n",SubTot);
printf("Tax %6.2f\n",Tax);
printf("Total $%6.2f\n\n",Total);
Last edited by LuciWiz : 31-Oct-2006 at 01:21.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|