My final assignment- Computer Science Basic Programming

I have created a tax calculator for homework-
It is a service request-To write a proper C Code and run the program according to the specifications.  Modify the C program so that the user inputs the purchase amount. Check the users 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.
I can't get my code to compile- any assistance will be greatly appreciated.

#include <stdio.h>
void main()
}
#define LaJolla 7.75
#define Delmar 7.25
#define Encinitas 7.75
{
int iResponse =(0);
//entering the variables in float;
float cost=0.0;
float Delmar=0.725;
float Encinitas-=0.75;
float LaJolla=.0775;
//entering
Output:
scanf(Sales tax amount 125.00 purchase for each)
*/ 
float user_input(){ 
float amount; 
printf("Please Enter the sales amountn"); 
scanf("%f", &amount); 
return amount; 
}\int main() {
printf("n\1\tLaJolla\n");
printf("n\2\tDelmar\n");
printf("n\3\tEncinitas\n");
printf("\nSelect a Store Category [1-3]:");
scanf(%d,&iResponse);
switch(IResponse){
Case 1:
//Calculate and print the store location, Sales, Tax rate, and Tax amount for LaJolla
printf("You selected LaJolla\n")
}
printf("enter sales price please\n")
Case 2:
//Calculate and print the store location, Sales, Tax rage, and Tax amount for Delmar
printf("You selected Delmar\n");
}
printf("enter sales price please\n");
Case 3:
//Calculate and print the store location, Sales, Tax rage, and Tax Amount for Encinitas
printf("You selected Encinitas\n");
}
printf("enter sales price please\n");
 
}
scanf ("%d",& cost);
  printf ("the Delmar sales tax is %.2f\n", Delmar * cost); 
  printf ("the Encinitas sales tax is %.2f\n", Encinitas * cost);
  printf ("the LaJolla sales tax is %.2f\n", LaJolla * cost);
  printf ("\n");
  printf ("the total for Delmar is %.2f\n", Delmar * cost * cost); 
  printf ("the total for Encinitas is %.2f\n", Encinitas * cost *  cost);
  printf ("the total for LaJolla is %.2f\n", LaJolla * cost * cost);
  getchar();
  return 0;
}

Open in new window

LaLa36Asked:
Who is Participating?
 
LaLa36Connect With a Mentor Author Commented:
This is my final product- it compiles and I figured out how to make the % stay in the right space
so here it is- The FINAL
Thank You for all your help
#include <stdio.h>
 
//      Declare a float variable for tax rate, purchase amount, total purchase amount, and sales tax
       
        float fDelMarSalesTax, fEncinitasSalesTax, fLaJollaSalesTax;
        float fDelMarSalesAmount, fEncinitasSalesAmount, fLaJollaSalesAmount;
        float fPurchaseAmount;
 
//      Declare the starting point
 
int main()
{
 
//      Set Local Sales Tax Rates
 
        #define fDelMarSalesTaxRate .0725
        #define fEncinitasSalesTaxRate .075
        #define fLaJollaSalesTaxRate .0775        
        
//      Initialize purchase amount in dollars
 
    
      printf("\n                *************************************\n");
      printf("\n                **                                 **\n");
      printf("\n                **       Kudler Tax Calculator     **\n");
      printf("\n                **                                 **\n");
      printf("\n                *************************************\n\n\n");
      printf("     How much was your purchase?  $");
      scanf("%.2f", &fPurchaseAmount);      
        
        
//      Calculate sales tax for Del Mar, Encinitas, La Jolla in dollars
 
 
  
   printf("Taxes:Delmar-7.5{1},LaJolla-7.25{2},Encinitas-7.75{3}");
   
   
   
   scanf("DelMar.0725%","Encinitas .0075%","La Jolla .0775%");
 
  
   printf("\n\tSelect 1-3 to see tax rates and press enter or 4 to exit:_ ");//Lets user know what tp input
   
 	
       fDelMarSalesTax = fPurchaseAmount * fDelMarSalesTaxRate;
       fEncinitasSalesTax = fPurchaseAmount * fEncinitasSalesTaxRate;
       fLaJollaSalesTax = fPurchaseAmount * fLaJollaSalesTaxRate;     
      
//      Calculate Total Sales Amount for Del Mar      
 
       fDelMarSalesAmount = fPurchaseAmount + fDelMarSalesTax;            
       fEncinitasSalesAmount = fPurchaseAmount + fEncinitasSalesTax;  
       fLaJollaSalesAmount = fPurchaseAmount + fLaJollaSalesTax;
            
//      Display Sales Tax for Del Mar, Encinitas, La Jolla on the Purchase Amount
 
       printf("\n\n              Purchase Amount      Sales Tax     Total Sales Amount\n");
       printf("              _______________      _________     __________________\n\n");
       printf("\n   Del Mar        %$125.00        $7.25 %%        $134.06 \n",fPurchaseAmount, fDelMarSalesTax, fDelMarSalesAmount);
       printf("\n   Encinitas      %$125.00        $7.5 %%         $134.37 \n",fPurchaseAmount, fEncinitasSalesTax, fEncinitasSalesAmount);
       printf("\n   La Jolla       %$125.00        $7.75 %%        $134.69 \n",fPurchaseAmount, fLaJollaSalesTax, fLaJollaSalesAmount); 
        
         
    printf("\n\n\nPress any key to exit program...");
    getchar();
    return 0;
}
 
   
	

Open in new window

0
 
mrjoltcolaCommented:
See my comments below, your program is a mish-mosh of problems. Take a look at each comment I made and consider it, clean up the code, then ask questions.
#include <stdio.h>
void main()                  // main() has no begin {
}                            // this line looks out of place, it is a end bracket, but for what?
#define LaJolla 7.75           // Put #define constants at the top, below #include, but before main()
#define Delmar 7.25
#define Encinitas 7.75
{
int iResponse =(0);                  // no need for parentheses
//entering the variables in float;
float cost=0.0;
float Delmar=0.725;
float Encinitas-=0.75;             // what is -= for ? -= is decrement, but you don't use it when declaring a variable
float LaJolla=.0775;
//entering
Output:
scanf(Sales tax amount 125.00 purchase for each)      // this line is not legal code, is it a comment or pseudocode?
*/                                // This line is an end comment, but there was no beginning comment /*
float user_input(){ 
float amount; 
printf("Please Enter the sales amountn"); 
scanf("%f", &amount); 
return amount; 
}\int main() {                       // what is this? a 2nd main() in your program? which one is which?
printf("n\1\tLaJolla\n");
printf("n\2\tDelmar\n");
printf("n\3\tEncinitas\n");
printf("\nSelect a Store Category [1-3]:");
scanf(%d,&iResponse);
switch(IResponse){
Case 1:
//Calculate and print the store location, Sales, Tax rate, and Tax amount for LaJolla
printf("You selected LaJolla\n")
}
printf("enter sales price please\n")
Case 2:
//Calculate and print the store location, Sales, Tax rage, and Tax amount for Delmar
printf("You selected Delmar\n");
}
printf("enter sales price please\n");
Case 3:
//Calculate and print the store location, Sales, Tax rage, and Tax Amount for Encinitas
printf("You selected Encinitas\n");
}
printf("enter sales price please\n");
 
}
scanf ("%d",& cost);
  printf ("the Delmar sales tax is %.2f\n", Delmar * cost); 
  printf ("the Encinitas sales tax is %.2f\n", Encinitas * cost);
  printf ("the LaJolla sales tax is %.2f\n", LaJolla * cost);
  printf ("\n");
  printf ("the total for Delmar is %.2f\n", Delmar * cost * cost); 
  printf ("the total for Encinitas is %.2f\n", Encinitas * cost *  cost);
  printf ("the total for LaJolla is %.2f\n", LaJolla * cost * cost);
  getchar();
  return 0;
}

Open in new window

0
 
LaLa36Author Commented:
Thank you- will do
0
Improved Protection from Phishing Attacks

WatchGuard DNSWatch reduces malware infections by detecting and blocking malicious DNS requests, improving your ability to protect employees from phishing attacks. Learn more about our newest service included in Total Security Suite today!

 
LaLa36Author Commented:
I appreciate your assistance- this is the 2nd code program I have done.  In this class, I have resigned myself that programming code is not my forte'.
This is the clean version (plus my comments- not sure if I need an Input/output block inserted)
#include <stdio.h>
#define LaJolla 7.75          
#define Delmar 7.25
#define Encinitas 7.75
{void main()
{
int iResponse 0;                  // no need for parentheses
//entering the variables in float;
float cost=0.0;
float Delmar=0.725;
float Encinitas=0.75;             // what is -= for ? -= is decrement, but you don't use it when declaring a variable
float LaJolla=.0775;
//entering
Output:
scanf(Sales tax amount 125.00 purchase for each)  (this is supposed to be a pseudocode)    // this line is not legal code, is it a comment or pseudocode?
                                                 // This line is an end comment, but there was no beginning comment /*
float user_input(){
float amount;
printf("Please Enter the sales amountn");
scanf("%f", &amount);
return amount;
{                       (I was trying to incorporate a menu view-L)// what is this? a 2nd main() in your program? which one is which?
printf("n\1\tLaJolla\n");
printf("n\2\tDelmar\n");
printf("n\3\tEncinitas\n");
printf("\nSelect a Store Category [1-3]:");
scanf(%d,&iResponse);
switch(IResponse){
Case 1:
//Calculate and print the store location, Sales, Tax rate, and Tax amount for LaJolla
printf("You selected LaJolla\n")
}
printf("enter sales price please\n")
Case 2:
//Calculate and print the store location, Sales, Tax rate, and Tax amount for Delmar
printf("You selected Delmar\n");
}
printf("enter sales price please\n");
Case 3:
//Calculate and print the store location, Sales, Tax rate, and Tax Amount for Encinitas
printf("You selected Encinitas\n");
}
printf("enter sales price please\n");
 }
scanf ("%d",& cost);
  printf ("the Delmar sales tax is %.2f\n", Delmar * cost);
  printf ("the Encinitas sales tax is %.2f\n", Encinitas * cost);
  printf ("the LaJolla sales tax is %.2f\n", LaJolla * cost);
  printf ("\n");
  printf ("the total for Delmar is %.2f\n", Delmar * cost * cost);
  printf ("the total for Encinitas is %.2f\n", Encinitas * cost *  cost);
  printf ("the total for LaJolla is %.2f\n", LaJolla * cost * cost);
  getchar();
  return 0;
}
 
0
 
mrjoltcolaCommented:
Are you familiar with indentation to make your code easier to read. If not, here is a sample. I recommend doing this on your whole program, and also putting some spacing / empty lines between functions so you can tell them apart. In your current code, it all runs together, so even for an experience programmer, it is hard to tell what your intent is.

I also suggest starting over with a smaller program and make sure it compiles from the very start. Then every time you add new code, test compile again. You have so many lines of code above, with so many errors, I cannot even tell where to start. Start over, create a new main(), add a single printf() statement to print a message, and make it compile and run. Get to that point before you start writing so many lines of code. Something like below.

Also, note, C is case sensitive, so where you used the word "Case", it is different than "case". Don't use Case, it is not the correct word. As a matter of fact, ALL C keywords are lowercase.


// Note the indentation below, each nested block is clearf
 
// The main, clearly commented
int main()
{
    int iResponse;
 
    printf("Enter a response>\n");
 
    scanf("%d", &iResponse);
    
    // A switch statement, clearly indented
    switch(iResponse)
    {
        // a nested case, clearly indented
        case 1:  printf("You entered 1\n");
                 break;
        case 2:  printf("You entered 2\n");
                 break;
    }
 
}  // end of main, clearly commented
 
 
// Clearly separate function, notice empty lines separating code for readability
float get_amount() {
 
   return 0.0;
}

Open in new window

0
 
mrjoltcolaConnect With a Mentor Commented:
Reminder, if you cannot write a 5 line C program and make it cleanly compile, DO NOT proceed until it compiles. A 5 line correct program is better than a 50 line mess that you can't fix.
0
 
LaLa36Author Commented:
Thank You- I didn't realize that it looked so bad.  I will work on it - Thank you again for your comments.  When I'm done- should I repost in the same question?
0
 
mrjoltcolaConnect With a Mentor Commented:
Hey, don't get me wrong, I am not being hard on you, just being honest. This is what a professor should tell you. I encourage you to try again, with what I told you in mind. Every programmer who took their 1st programming class did the same thing you did, including me. :)

Now, step back, start over, and I will help you every step. You will have a working program shortly, and have learned some valuable lessons about how to break the problem down into smaller parts. By starting over, and compiling every step of the way, you are helping yourself by reducing  your program of fixing a 50 line program with lots of errors.

0
 
mrjoltcolaConnect With a Mentor Commented:
>>When I'm done- should I repost in the same question?

Yes, continue in this question.
0
 
LaLa36Author Commented:
Ok, This is just driving me crazy - I did an inital code and my instructor said it was great- Now I just feel like an idiot.
Your not being hard on me- this is something I have to do and to understand it to keep the knowledge is why I went back to college in the first place.  It helps me- Don't be easy-L
I am trying to insert comments into my tax calculator & have it calculate the tax
Starting from beginning
This is my original program for the tax calculator - do you think I can build on this?


#include <stdio.h>
 
/*Using define macros for assigning tax to different stores */
#define DelMar 7.25
#define Encinitas 7.5
#define LaJolla 7.75
 
/*
Input:
" Del Mar - 7.25%
" Encinitas - 7.5%
" La Jolla - 7.75%
 
Output:
The sales tax amount for each store of the 125.00 Purchase for each.
*/
int main(){
// The total sales for each store is
float sales = 125.00;
//Display Program Header
printf("Tax Calculator for Kudler Fine Foods for All locations\n\n\n");
 
//Calculate and print the Sales and Tax for Del Mar
printf("The Sales amount for Del Mar Store is %.2f\n");
printf("The Sales Tax for Del Mar Store is %.2f\n\n", sales * DelMar/100);
//Calculate and print the Sales and Tax for Encinitas
printf("The Sales amount for Encinitas Store is %.2f\n");
printf("The Sales Tax for Encinitas Store is %.2f\n\n", sales * Encinitas/100);
//Calculate and print the Sales and Tax for La Jolla
printf("The Sales amount for La Jolla Store is %.2f\n");
printf("The Sales Tax for La Jolla Store is %.2f\n", sales * LaJolla/100);
 
 
return 0;
 
}

Open in new window

0
 
mrjoltcolaConnect With a Mentor Commented:
Sure. Build 1 step at a time, and everytime you make changes, test the compile.

Backup your program to a safe copy each time as well, so if you get really lost, you can go back to the prior version that worked.
0
 
LaLa36Author Commented:
I 'm flowing now- how does this look so far?
#include <stdio.h>
void main() 
#define LaJolla 7.75           
#define Delmar 7.25
#define Encinitas 7.75
{
Float tax variables;
Prompt float tax(3)={"7.5,7.25,7.75"];
Scanf("Del Mar .0725%","Encinitas .0075%","La Jolla .0775%");
float purchaseamount;
 	
                   //Sales calculation for Del Mar, Encinitas, La Jolla in dollars
 
Sales tax amount 125.00 for each store purchase
float amount;
float user_input()
printf (Enter sales amount/n");
scanf (%f", &sale amount)
 
}
 
Display beginning of program and selections
	printf("\n\t\t\tKudler Fine Foods Tax Calculator\n");
 
	
	printf("\n\t1. Delmar\n");
	printf("\t2. Encinitas\n");
	printf("\t3. LaJolla\n");
	printf("\t4. End Program\n");
	
	printf("\n\tSelect 1-3 to see tax rates and press enter or 4 to exit: ");//Lets user know what to input
	do {    
	//Begin loop  

Open in new window

0
 
LaLa36Author Commented:
I just remembered- Does it matter what type of Compiler I work with?
0
 
mrjoltcolaConnect With a Mentor Commented:
Does your code compile?
0
 
LaLa36Author Commented:
I got it to compile and created a box- it actually looks ok.  I wanted to put the percentages in the box but I don't know how- Just glad it works
Maybe a little cramped-Let me know your thoughts
Thank you so much
#include <stdio.h>
 
//      Declare a float variable for tax rate, purchase amount, total purchase amount, and sales tax
       
        float fDelMarSalesTax, fEncinitasSalesTax, fLaJollaSalesTax;
        float fDelMarSalesAmount, fEncinitasSalesAmount, fLaJollaSalesAmount;
        float fPurchaseAmount;
 
//      Declare the starting point
 
int main()
{
 
//      Set Local Sales Tax Rates
 
        #define fDelMarSalesTaxRate .0725
        #define fEncinitasSalesTaxRate .075
        #define fLaJollaSalesTaxRate .0775        
        
//      Initialize purchase amount in dollars
 
    
      printf("\n                *************************************\n");
      printf("\n                **                                 **\n");
      printf("\n                **       Kudler Tax Calculator     **\n");
      printf("\n                **                                 **\n");
      printf("\n                *************************************\n\n\n");
      printf("     How much was your purchase?  $");
      scanf("%.2f", &fPurchaseAmount);      
        
        
//      Calculate sales tax for Del Mar, Encinitas, La Jolla in dollars
 
 
  
   printf("float tax:Delmar-7.5{1},LaJolla-7.25{2},Encinitas-7.75{3}");
   
   
   
   scanf("DelMar.0725%","Encinitas .0075%","La Jolla .0775%");
 
  
   printf("\n\tSelect 1-3 to see tax rates and press enter or 4 to exit:_ ");//Lets user know what tp input
   
 	
       fDelMarSalesTax = fPurchaseAmount * fDelMarSalesTaxRate;
       fEncinitasSalesTax = fPurchaseAmount * fEncinitasSalesTaxRate;
       fLaJollaSalesTax = fPurchaseAmount * fLaJollaSalesTaxRate;     
      
//      Calculate Total Sales Amount for Del Mar      
 
       fDelMarSalesAmount = fPurchaseAmount + fDelMarSalesTax;            
       fEncinitasSalesAmount = fPurchaseAmount + fEncinitasSalesTax;  
       fLaJollaSalesAmount = fPurchaseAmount + fLaJollaSalesTax;
            
//      Display Sales Tax for Del Mar, Encinitas, La Jolla on the Purchase Amount
 
       printf("\n\n              Purchase Amount      Sales Tax     Total Sales Amount\n");
       printf("              _______________      _________     __________________\n\n");
       printf("\n   Del Mar         $%.2f            $%.2f        $%.2f\n",fPurchaseAmount, fDelMarSalesTax, fDelMarSalesAmount);
       printf("\n   Encinitas       $%.2f            $%.2f        $%.2f\n",fPurchaseAmount, fEncinitasSalesTax, fEncinitasSalesAmount);
       printf("\n   La Jolla        $%.2f            $%.2f        $%.2f\n",fPurchaseAmount, fLaJollaSalesTax, fLaJollaSalesAmount); 
       
         
    printf("\n\n\nPress any key to exit program...");
    getchar();
    return 0;
}
 
   
	

Open in new window

0
 
LaLa36Author Commented:
None
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.