Member Avatar for flip.phinoi

Hello guys,

I'm new here and hoping to get some kind of help with my code. This code is to calculate sales tax for specific store. I've got the most part of the code working, but I have to modify it so that it continues to loop until the user decides to exit the program.

I would appreciate any help and thanks in advance!

#include <stdio.h>
#include <stdlib.h>

main()

{

//Define the Variables and their Values

float fltDelMar = .0725f;	           //Defines Del Mar's tax percentage
float fltEncinitas = .075f;	           //Defines Encinitas' tax percentage
float fltLaJolla = .0775f;	           //Defines La Jolla's tax percentage
float fltAmount;	                   //Defines the sale amount
char chrPercent = '\45';	           //Defines a % sign for usage in the program
int ui;				                   //Defines an integer to hold the scanf amount function from user input to be verfied
char storelocation;                    //Defines the storelocatoin character

//Displays information about the tax calculator program
printf("Kudler Fine Foods Tax Calculator\n");
printf("\nThis program will calculate the taxable amount based \non the inputed amount for the selected Kudler stores.\n");
printf("\nTax breakdown below:");
printf("\nDel Mar - 7.25%c tax rate", chrPercent);
printf("\nEncinitas - 7.5%c tax rate", chrPercent);
printf("\nLa Jolla - 7.75%c tax rate\n", chrPercent);

{
//Allows the user to enter an amount to be taxed
printf("\nPlease enter the purchase amount in dollars & cents, then press [ENTER]:$");
    ui = scanf("%f",&fltAmount); 
    fflush(stdin);  
    
     if (ui <= 0) 
    {
        printf("That is not a valid purchase amount.\n");
    }
    else
    {

//Allows the user to select the store
printf("\nPlease select the store to compute tax:\n");
printf("1) DelMar \n2) Encinitas \n3) La Jolla \n");
printf("Select 1, 2, 3: "); 

//Calculates the tax rates as well as totals the transaction
		scanf("%c",&storelocation);
		fgetc(stdin); 
		printf("%c",&storelocation);
		    if (storelocation == '1')
            {
            printf("\nDel Mar: Tax= $%.2f, Total= $%.2f\n", fltDelMar * fltAmount, (fltDelMar * fltAmount) + fltAmount);
            }
            else if (storelocation == '2')
            {
            printf("\nEncinitas: Tax= $%.2f, Total= $%.2f\n", fltEncinitas * fltAmount, (fltEncinitas * fltAmount) + fltAmount);
            }
            else if (storelocation == '3')
            {
            printf("\nLa Jolla: Tax= $%.2f, Total= $%.2f\n", fltLaJolla * fltAmount, (fltLaJolla * fltAmount) + fltAmount);
            }
            else
            {
			printf("Entry not acceptable, please choose another selection.");
		    }
}

//Requires the user to press [ENTER] to exit the program
printf("\nThank you for using the tax calculator!\nHave a nice day!!!\n");
printf("\nPress [ENTER] to exit the program...");

getchar();
}
}
Member Avatar for flip.phinoi

Please, post your code again with code tags:
[code=c++] sources

[/code]
It's impossible to read unformatted raw codes...
Read this before:
http://www.daniweb.com/forums/announcement8-3.html

Sorry about that... noobie :)

#include <stdio.h>
#include <stdlib.h>

main()

{

//Define the Variables and their Values

float fltDelMar = .0725f;	           //Defines Del Mar's tax percentage
float fltEncinitas = .075f;	           //Defines Encinitas' tax percentage
float fltLaJolla = .0775f;	           //Defines La Jolla's tax percentage
float fltAmount;	                   //Defines the sale amount
char chrPercent = '\45';	           //Defines a % sign for usage in the program
int ui;				                   //Defines an integer to hold the scanf amount function from user input to be verfied
char storelocation;                    //Defines the storelocatoin character

//Displays information about the tax calculator program
printf("Kudler Fine Foods Tax Calculator\n");
printf("\nThis program will calculate the taxable amount based \non the inputed amount for the selected Kudler stores.\n");
printf("\nTax breakdown below:");
printf("\nDel Mar - 7.25%c tax rate", chrPercent);
printf("\nEncinitas - 7.5%c tax rate", chrPercent);
printf("\nLa Jolla - 7.75%c tax rate\n", chrPercent);

{
//Allows the user to enter an amount to be taxed
printf("\nPlease enter the purchase amount in dollars & cents, then press [ENTER]:$");
    ui = scanf("%f",&fltAmount); 
    fflush(stdin);  
    
     if (ui <= 0) 
    {
        printf("That is not a valid purchase amount.\n");
    }
    else
    {

//Allows the user to select the store
printf("\nPlease select the store to compute tax:\n");
printf("1) DelMar \n2) Encinitas \n3) La Jolla \n");
printf("Select 1, 2, 3: "); 

//Calculates the tax rates as well as totals the transaction
		scanf("%c",&storelocation);
		fgetc(stdin); 
		printf("%c",&storelocation);
		    if (storelocation == '1')
            {
            printf("\nDel Mar: Tax= $%.2f, Total= $%.2f\n", fltDelMar * fltAmount, (fltDelMar * fltAmount) + fltAmount);
            }
            else if (storelocation == '2')
            {
            printf("\nEncinitas: Tax= $%.2f, Total= $%.2f\n", fltEncinitas * fltAmount, (fltEncinitas * fltAmount) + fltAmount);
            }
            else if (storelocation == '3')
            {
            printf("\nLa Jolla: Tax= $%.2f, Total= $%.2f\n", fltLaJolla * fltAmount, (fltLaJolla * fltAmount) + fltAmount);
            }
            else
            {
			printf("Entry not acceptable, please choose another selection.");
		    }
}

//Requires the user to press [ENTER] to exit the program
printf("\nThank you for using the tax calculator!\nHave a nice day!!!\n");
printf("\nPress [ENTER] to exit the program...");
getchar();
}
}

Put your code in between a do - while statement. Like this one:

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
   int loop = 0;
	
   do
   {
        cout << "This is the " << loop << ". run." << endl;
        loop++;
        cout << "Do you want to continue? - Hit 'ENTER' to quit" << endl;
   }
   while( _getch() != 13 ); // or try  getch() 
  
   return 0;
}

This only works with Windows, as far as I know there is now such library as "conio.h" for Linux. One more thing 13 is the ASCII code of 'ENTER' or carriage return. ASCII Character Map, this might be helpful.Good luck.

Sorry about that... noobie :)

Not an excuse. There are at least 6 places where CODE tags are suggested/described. The first is in the rules you were asked to read when you signed up. The last is right on the background of the input box you typed your message into.

#include <conio.h>
...
   while( _getch() != 13 ); // or try  getch()

This only works with Windows...

Completely non-standard and not recommended. You should recommend something anyone can use, like cin.get() or some other C++ input function that is part of the language. And 13 is '\n', which should also be used.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.