Menu for Kudler Fine Foods

Create a menu to display a tax calc for the store specified based on t

Page 1 of 1

4 Replies - 4055 Views - Last Post: 08 June 2008 - 11:43 PM Rate Topic: -----

#1 MustangAlice   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 10-May 08

Menu for Kudler Fine Foods

Posted 08 June 2008 - 05:56 PM

I'm attempting to create a program so that the user inputs the purchase amount. I need to check the users input for validity. Provide the user the ability to select from a menu which store to use for the tax calculation. Calculate and display the tax amount for the store selected and the total sale amount for that store. I attempted below however continue to receive several errors.
Please help...see my code below:

/*
CSS 561 Week#6     
June 9, 2008                                       
SR-kf-008, Change Request#2                          
Kudler Fine Foods               
Modify the C program so that the user inputs the purchase amount.
Check the userís input for validity. 
Have the user select from a menu which store to use for the tax calculation
Calculate and display the tax amount for the store selected 
and the total sale amount for that store

Tax Calculations: Del Mar=7.25%,Encinitas=7.50%, La Jolla= 7.75%
*/

/* Standard I/O libraries used */

#include <stdio.h>
#include <stdlib.h>
IsDollar (char*chrDollarAmount);  //Amount input by user

int main (void)
{

char charAmount[15] = {'\0'};	// String amount, initialized to 0; will hold the input from the user

double dblAmount = 0.0;		// numeric representation of user input

double DelMar_TaxRate = 7.25;	// Tax Rate for Del Mar

double Encinitas_TaxRate = 7.50;// Tax Rate for Encinitas

double LaJolla_TaxRate = 7.75;	// Tax Rate for LaJolla

double dblTaxAmount_DelMar = 0.0, double dblTaxAmount_Encinitas = 0.0, double dblTaxAmount_LaJolla = 0.0;  
//Totals
double dblTotalDelMar = 0.00; 		//Del Mar Total;
double dblTotalEncinitas = 0.00;	//Encinitas Total;
double dblTotalLaJolla = 0.00; 		//La Jolla Total;
//End of variable declaration


int i;
int validInput = 0;
int intChoice = 0;
char charUser = '\0';

printf("\n\nKudler Fine Foods Tax Calculator\n");	// Title
do
{
printf("\n\nPlease Enter The Purchase Amount:\n $");	// Prompt user to enter the amount

scanf("%s",charAmount);	// Wait for the user to input, 15 character maximum

if (IsDollar(charAmount) == 0);
{

dblAmount = atof(CharAmount);

printf("\nYou have entered $%.2f. Is this correct? (Y or N): ", dblAmount);

scanf("%c",&charUser);
}
				
}
while ((charUser != 'Y') && (charUser != 'y'));
while IsDollar (charAmount) = 1;	//validate input is a valid dollar amount

{
if ( ((charAmount[i] < '0') || (charAmount[i] > '9')) && // check to see if not numeric
(charAmount[i] != '.'))				// only allowed non numeric
validInput = 0;
}

{
if (validInput == 0)	// Not valid

printf("\n\nError! Invalid Amount: %s\n", charAmount);	// Display error 
fflush(stdin);
 							// End program
}

dblAmount = atof(charAmount);
printf("\n----------------------------------------------------------");
printf("\nPlease select 1, 2, or 3 for the store location\n");
printf("\n----------------------------------------------------------");

printf("\n1. DelMar");
printf("\n2. Encinitas");
printf("\n3. La Jolla");
scanf("%i", intChoice);
if ((intChoice<1) || (intChoice>3))
{
intvalidInput = 1;
printf("\nInvalid entry, please enter a valid selection of 1-3");
}
}
while (intvalidInput==1);	// Validate the entery is 1, 2 or 3 only

dblDelMarTax = (dblAmount * DelMar_TaxRate)/100;	// Tax for Del Mar
dblEncinitasTax = (dblAmount * Encinitas_TaxRate)/100;	// Tax for Encinitas
dblLaJollaTax = (dblAmount * LaJolla_TaxRate)/100;	// Tax for La Jolla

dblTaxAmount_DelMar=dblAmount * dblDelMar_TaxRate;	// calc tax per location
dblTaxAmount_Encinitias=dblAmount * dblEncinitas_TaxRate; // calc tax per location
dblTaxAmount_LaJolla=dblAmount * dblLaJolla_TaxRate;	// calc tax per location

dblTotalDelMar=dblAmount+dblDelMar_TaxRate;		//calc total amt
dblTotalEncinitas=dblAmount+dblEncinitas_TaxRate;	//calc total amt
dblTotalLaJolla=dblAmount+dblLaJolla_TaxRate;		//calc total amt

printf("\nBased on your input of $%.2f", dblAmount);
printf("\---------------------------------------------");
printf("\Store\t\tTax Amount\tTotal");
//Display information entered by the user
switch (intChoice)
{
Case1:
	printf("\nDelMar\t$%.2f\t\t$%.2f",dblTaxAmount_DelMar,dblTotalDelMar);
break;
Case2:
	printf("\nEncinitas\t$%.2f\t\t$%.2f",dblTaxAmount_Encinitas,dblTotalEncinitas);
break;
Case3:
	printf("\nLaJolla\t$%.2f\t\t$%.2f",dblTaxAmount_LaJolla,dblTotalLaJolla);
break;
default
}	
printf("\n------------------------------------------------");
//Promt the user to exit
fflush(stdin);
printf("\nPress any key to exit the screen");
getchar();
return 0;	// Wait for char to end
}
}


*edit: Please use code tags in the future, thanks! :code:

This post has been edited by Martyr2: 08 June 2008 - 06:05 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Menu for Kudler Fine Foods

#2 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1433
  • View blog
  • Posts: 11,006
  • Joined: 06-February 08

Re: Menu for Kudler Fine Foods

Posted 08 June 2008 - 06:20 PM

You have a massive amount of syntax errors in there. Code indentation is a must with code this length, to see where loops begin/end (I don't know if you used it or not, but you need to :code: for me to see that.

I fixed up a bunch of your syntax errors, but only quickly ~ there are probably still errors in there, I can't find them since I don't have the time, and your code is barely readable.

/*
CSS 561 Week#6
June 9, 2008
SR-kf-008, Change Request#2
Kudler Fine Foods
Modify the C program so that the user inputs the purchase amount.
Check the userís input for validity.
Have the user select from a menu which store to use for the tax calculation
Calculate and display the tax amount for the store selected
and the total sale amount for that store

Tax Calculations: Del Mar=7.25%,Encinitas=7.50%, La Jolla= 7.75%
*/

/* Standard I/O libraries used */

#include <stdio.h>
#include <stdlib.h>
bool IsDollar (char*chrDollarAmount); //Amount input by user

// GLOBAL VARIABLES, ACCESSIBLE FROM OTHER FUNCTIONS!
char charAmount[15] = {'\0'}; // String amount, initialized to 0; will hold the input from the user

double dblAmount = 0.0; // numeric representation of user input

double DelMar_TaxRate = 7.25; // Tax Rate for Del Mar

double Encinitas_TaxRate = 7.50;// Tax Rate for Encinitas

double LaJolla_TaxRate = 7.75; // Tax Rate for LaJolla

// THE POINT OF SINGLE LINE DEFINITIONS IS THAT THEY ARE ALL THE SAME TYPE,LIKE SO
double dblTaxAmount_DelMar = 0.0, dblTaxAmount_Encinitas = 0.0, dblTaxAmount_LaJolla = 0.0;
//Totals
double dblTotalDelMar = 0.00; //Del Mar Total;
double dblTotalEncinitas = 0.00; //Encinitas Total;
double dblTotalLaJolla = 0.00; //La Jolla Total;
//End of variable declaration



int main (void)
{


int i;
int validInput = 0;
int intChoice = 0;
char charUser = '\0';

printf("\n\nKudler Fine Foods Tax Calculator\n"); // Title
do
{
printf("\n\nPlease Enter The Purchase Amount:\n $"); // Prompt user to enter the amount

char *charAmount; // CHAR TYPE?
// %c
scanf("%c",charAmount); // Wait for the user to input, 15 character maximum

if (IsDollar(charAmount) == 0);
{

dblAmount = atof(charAmount);

printf("\nYou have entered $%.2f. Is this correct? (Y or N): ", dblAmount);

scanf("%c",&charUser);
}

// shouldnt be } here
while ((charUser != 'Y') && (charUser != 'y')){ // MISSED {
// == IS THE COMPARISON OPERATOR, = IS ASSIGNMENT
while (IsDollar (charAmount) == 1) //validate input is a valid dollar amount

{
if ( ((charAmount[i] < '0') || (charAmount[i] > '9'))// check to see if not numeric
&&(charAmount[i] != '.')) // only allowed non numeric
validInput = 0;
}

{
if (validInput == 0) // Not valid

printf("\n\nError! Invalid Amount: %s\n", charAmount); // Display error
fflush(stdin);
// End program
}

dblAmount = atof(charAmount);
printf("\n----------------------------------------------------------");
printf("\nPlease select 1, 2, or 3 for the store location\n");
printf("\n----------------------------------------------------------");

printf("\n1. DelMar");
printf("\n2. Encinitas");
printf("\n3. La Jolla");
// %d FOR INT TYPE
scanf("%D", intChoice);
if ((intChoice<1) || (intChoice>3))
{
int validInput = 1; // MISSED A SPACE
printf("\nInvalid entry, please enter a valid selection of 1-3");
}
}
// NO NEED FOR ; AFTER WHILE LOOP
while (validInput==1) // Validate the entery is 1, 2 or 3 only
{ // MISSED THIS!
    // MISSED double KEYWORD FOR ALL OF THE FOLLOWING:
double dblDelMarTax = (dblAmount * DelMar_TaxRate)/100; // Tax for Del Mar
double dblEncinitasTax = (dblAmount * Encinitas_TaxRate)/100; // Tax for Encinitas
double dblLaJollaTax = (dblAmount * LaJolla_TaxRate)/100; // Tax for La Jolla

double dblTaxAmount_DelMar=dblAmount * DelMar_TaxRate; // calc tax per location
double dblTaxAmount_Encinitias=dblAmount * Encinitas_TaxRate; // calc tax per location
double dblTaxAmount_LaJolla=dblAmount * LaJolla_TaxRate; // calc tax per location

double dblTotalDelMar=dblAmount+DelMar_TaxRate; //calc total amt
double dblTotalEncinitas=dblAmount+Encinitas_TaxRate; //calc total amt
double dblTotalLaJolla=dblAmount+LaJolla_TaxRate; //calc total amt

printf("\nBased on your input of $%.2f", dblAmount);
printf("\---------------------------------------------");
printf("\Store\t\tTax Amount\tTotal");
//Display information entered by the user
switch (intChoice)
{
case 1:
printf("\nDelMar\t$%.2f\t\t$%.2f",dblTaxAmount_DelMar,dblTotalDelMar);
break;
case 2:
printf("\nEncinitas\t$%.2f\t\t$%.2f",dblTaxAmount_Encinitas,dblTotalEncinitas);
break;
case 3:
printf("\nLaJolla\t$%.2f\t\t$%.2f",dblTaxAmount_LaJolla,dblTotalLaJolla);
break;
default:
printf("\n------------------------------------------------");
} // END SWITCH
} // END WHILE
} // END WHILE
//Promt the user to exit
fflush(stdin);
printf("\nPress any key to exit the screen");
getchar();
return 0; // Wait for char to end

}

Was This Post Helpful? 0
  • +
  • -

#3 MustangAlice   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 10-May 08

Re: Menu for Kudler Fine Foods

Posted 08 June 2008 - 09:13 PM

Thank you for the suggestions. I have reviewed the code and updated the suggesstions. I'm still receiving several errors.
Please point me in the right direction...I'm getting frustrated with myself.
Thank you.

/*
CSS 561 Week#6
June 9, 2008
SR-kf-008, Change Request#2
Kudler Fine Foods
Modify the C program so that the user inputs the purchase amount.
Check the userís input for validity.
Have the user select from a menu which store to use for the tax calculation
Calculate and display the tax amount for the store selected
and the total sale amount for that store

Tax Calculations: Del Mar=7.25%,Encinitas=7.50%, La Jolla= 7.75%
*/

/* Standard I/O libraries used */

#include <stdio.h>
#include <stdlib.h>
int IsDollar (char*chrDollarAmount); //Amount input by user

int char charAmount[15] = {'\0'}; // String amount, initialized to 0; will hold the input from the user

double dblAmount = 0.0; // numeric representation of user input

double DelMar_TaxRate = 7.25; // Tax Rate for Del Mar

double Encinitas_TaxRate = 7.50;// Tax Rate for Encinitas

double LaJolla_TaxRate = 7.75; // Tax Rate for LaJolla

double dblTaxAmount_DelMar = 0.0, dblTaxAmount_Encinitas = 0.0, dblTaxAmount_LaJolla = 0.0;
//Totals
double dblTotalDelMar = 0.00; //Del Mar Total;
double dblTotalEncinitas = 0.00; //Encinitas Total;
double dblTotalLaJolla = 0.00; //La Jolla Total;
//End of variable declaration
int main ()
{

int i;
int validInput = 0;
int intChoice = 0;
char charUser = '\0';
int char charAmount[15] = {'\0'}; // String amount, initialized to 0; will hold the input from the user

printf("\n\nKudler Fine Foods Tax Calculator\n"); // Title
do

printf("\n\nPlease Enter The Purchase Amount:\n $"); // Prompt user to enter the amount

int char *charAmount;

scanf("%c",charAmount); // Wait for the user to input, 15 character maximum

if (IsDollar(charAmount) == 0);
{

dblAmount = atof(charAmount);

printf("\nYou have entered $%.2f. Is this correct? (Y or N): ", dblAmount);

scanf("%c",&charUser);
}
{
while ((charUser != 'Y') && (charUser != 'y'))
{
WHILE (IsDollar (charAmount) == 1) //validate input is a valid dollar amount

{
if ( ((charAmount[i] < '0') || (charAmount[i] > '9'))// check to see if not numeric
&&(charAmount[i] != '.')) // only allowed non numeric
validInput = 0;
}

{
if (validInput == 0) // Not valid

printf("\n\nError! Invalid Amount: %s\n", charAmount); // Display error
fflush(stdin);
// End program
}

dblAmount = atof(charAmount);
printf("\n----------------------------------------------------------");
printf("\nPlease select 1, 2, or 3 for the store location\n");
printf("\n----------------------------------------------------------");

printf("\n1. DelMar");
printf("\n2. Encinitas");
printf("\n3. La Jolla");
scanf("%d", intChoice);
if ((intChoice<1) || (intChoice>3))
{
int validInput = 1;
printf("\nInvalid entry, please enter a valid selection of 1-3");
}
}
while (validInput==1) // Validate the entry is 1, 2 or 3 only
{
double dblDelMarTax = (dblAmount * dblDelMar_TaxRate)/100; // Tax for Del Mar
double dblEncinitasTax = (dblAmount * dblEncinitas_TaxRate)/100; // Tax for Encinitas
double dblLaJollaTax = (dblAmount * dblLaJolla_TaxRate)/100; // Tax for La Jolla

double dblTaxAmount_DelMar=dblAmount * dblDelMar_TaxRate; // calc tax per location
double dblTaxAmount_Encinitias=dblAmount * dblEncinitas_TaxRate; // calc tax per location
double dblTaxAmount_LaJolla=dblAmount * dblLaJolla_TaxRate; // calc tax per location

double dblTotalDelMar=dblAmount+dblDelMar_TaxRate; //calc total amt
double dblTotalEncinitas=dblAmount+dblEncinitas_TaxRate; //calc total amt
double dblTotalLaJolla=dblAmount+dblLaJolla_TaxRate; //calc total amt

printf("\nBased on your input of $%.2f", dblAmount);
printf("\---------------------------------------------");
printf("\Store\t\tTax Amount\tTotal"); //Display information entered by the user
switch (intChoice)
{
case 1:
printf("\nDelMar\t$%.2f\t\t$%.2f",dblTaxAmount_DelMar,dblTotalDelMar);
break;
case 2:
printf("\nEncinitas\t$%.2f\t\t$%.2f",dblTaxAmount_Encinitas,dblTotalEncinitas);
break;
case 3:
printf("\nLaJolla\t$%.2f\t\t$%.2f",dblTaxAmount_LaJolla,dblTotalLaJolla);
break;
default:
printf("\n------------------------------------------------");
}
}
}
//Promt the user to exit
fflush(stdin);
printf("\nPress any key to exit the screen");
getchar();
return 0; // Wait for char to end

}
Was This Post Helpful? 0
  • +
  • -

#4 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3202
  • View blog
  • Posts: 19,234
  • Joined: 14-September 07

Re: Menu for Kudler Fine Foods

Posted 08 June 2008 - 11:31 PM

specific information regarding errors helps us help you...
Was This Post Helpful? 0
  • +
  • -

#5 MustangAlice   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 10-May 08

Re: Menu for Kudler Fine Foods

Posted 08 June 2008 - 11:43 PM

Here is one of the error messages:
line 23: Parse Error, expecting `SEP'
'int char charAmount[15] = {'\0'}'
aborting compile
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1