Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a C++ Expert!

Join 244,308 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 824 people online right now. Registration is fast and FREE... Join Now!




Tax Program using Miracle C

 
Reply to this topicStart new topic

Tax Program using Miracle C, Ask for purchase price , tax amt and total in 3 locations

idgirl
7 Jan, 2009 - 04:48 PM
Post #1

New D.I.C Head
*

Joined: 24 Feb, 2008
Posts: 19


My Contributions
Hi,
My code so far works great. I would like to add in something for :
if a letter or character is entered for the price
The program would say invalid input and ask for the price again
And
If a number other than 1-3(locations), or a letter or character is entered
ask for location again

I don't know if it is even possible to do what I want. What I have so far is what we had to do for the assignment, I just wanted to add the rest in.

cpp
#include <stdio.h>  // Includes standard input/output//


void main () //Tells us that there is no value when the program exits//
{


float Price = 0.00;
float DelMar = 7.25;
float Encinitas = 7.5;
float LaJolla = 7.75;
int Location;

printf (" Welcome to Kudler Tax Program\n\n");
printf(" Purchase Price is $125.00\n");

while (Price != 125.0) // Initiates the While loop for asking the user to input a Price and then if
{
printf("\n\nEnter Price: "); // Asking user to input price//
scanf("%f", &Price); //Reads in the purchase price and outputs it to the screen//
}


printf("\n\n"); // Allows for blank lines, in this case 2. Each N represents a line//

printf("1\tDel Mar\n"); // Tells user that Delmar choice is number one and that the city name is tabbed over from its location number//

printf("2\tEncinitas\n"); // Tells user that Encinitas choice is number Two and that the city name is tabbed over from its location number//

printf("3\tLa Jolla\n\n"); // Tells user that LaJolla choice is number Three and that the city name is tabbed over from its location number//

printf("Choose Location: "); // Asking user to choose a location for the tax amount//
scanf ("%d", &Location); //Reads the location and outputs it to the screen//



if( Location == 1)
printf ("\nDelMar 1: Tax = $%4.2f and Total Purchase = $%4.2f\n\n", (Price*(DelMar/100)), (Price+(Price*(DelMar/100))) ); //Compiles the purchase, calculates the tax and adds them for the total//
if (Location == 2)
printf ("\nEncinitas 2: Tax = $%4.2f and Total Purchase = $%4.2f\n\n", (Price*(Encinitas/100)), (Price+(Price*(Encinitas/100))) ); //Compiles the purchase, calculates the tax and adds them for the total//
if (Location == 3)
printf ("\nLaJolla 3: Tax = $%4.2f and Total Purchase = $%4.2f\n\n", (Price*(LaJolla/100)), (Price+(Price*(LaJolla/100))) ); //Compiles the purchase, calculates the tax and adds them for the total//


printf ("\nPress enter to close window and exit\n"); // Tells the compiler the user is done with the program//

getchar (); // Tells compiler to keep program open in order to close out of the program//
}// End//


** Edit ** code.gif

User is offlineProfile CardPM
+Quote Post


yunusabd
RE: Tax Program Using Miracle C
7 Jan, 2009 - 06:20 PM
Post #2

D.I.C Head
**

Joined: 25 Oct, 2008
Posts: 66



Thanked: 1 times
My Contributions
Sorry about that I did not notice that you already have the code blocks

This post has been edited by yunusabd: 7 Jan, 2009 - 06:23 PM
User is offlineProfile CardPM
+Quote Post

yunusabd
RE: Tax Program Using Miracle C
7 Jan, 2009 - 06:27 PM
Post #3

D.I.C Head
**

Joined: 25 Oct, 2008
Posts: 66



Thanked: 1 times
My Contributions
CODE
#include <stdio.h> // Includes standard input/output//


void main () //Tells us that there is no value when the program exits//
{


   float Price = 0.00;
   float DelMar = 7.25;
   float Encinitas = 7.5;
   float LaJolla = 7.75;
   int Location;

   printf (" Welcome to Kudler Tax Program\n\n");
   printf(" Purchase Price is $125.00\n");

while (Price != 125.0) // Initiates the While loop for asking the user to input a  Price and then if
{
   printf("\n\nEnter Price: "); // Asking user to input price//
   scanf("%f", &Price); //Reads in the purchase price and outputs it to the screen//
}


   printf("\n\n"); // Allows for blank lines, in this case 2. Each N represents a line//

   printf("1\tDel Mar\n"); // Tells user that Delmar choice is number one and that the city name is tabbed over from its location number//

   printf("2\tEncinitas\n"); // Tells user that Encinitas choice is number Two and that the city name is tabbed over from its location number//

   printf("3\tLa Jolla\n\n"); // Tells user that LaJolla choice is number Three and that the city name is tabbed over from its location number//

   printf("Choose Location: "); // Asking user to choose a location for the tax amount//
   scanf ("%d", &Location); //Reads the location and outputs it to the screen//



if( Location == 1)
   printf ("\nDelMar 1: Tax = $%4.2f and Total Purchase = $%4.2f\n\n", (Price*(DelMar/100)), (Price+(Price*(DelMar/100))) ); //Compiles the purchase, calculates the tax and adds them for the total//
if (Location == 2)
   printf ("\nEncinitas 2: Tax = $%4.2f and Total Purchase = $%4.2f\n\n", (Price*(Encinitas/100)), (Price+(Price*(Encinitas/100))) ); //Compiles the purchase, calculates the tax and adds them for the total//
if (Location == 3)
   printf ("\nLaJolla 3: Tax = $%4.2f and Total Purchase = $%4.2f\n\n", (Price*(LaJolla/100)), (Price+(Price*(LaJolla/100))) ); //Compiles the purchase, calculates the tax and adds them for the total//


   printf ("\nPress enter to close window and exit\n"); // Tells the compiler the user is done with the program//

   getchar (); // Tells compiler to keep program open in order to close out of the program//
}// End//



The last block is only /code , you put \endcode

This post has been edited by yunusabd: 7 Jan, 2009 - 06:29 PM
User is offlineProfile CardPM
+Quote Post

yunusabd
RE: Tax Program Using Miracle C
7 Jan, 2009 - 07:53 PM
Post #4

D.I.C Head
**

Joined: 25 Oct, 2008
Posts: 66



Thanked: 1 times
My Contributions
Replace your if statements at the end of your code with this




CODE
  switch (Location){
      
       case 1 : printf ("\nDelMar 1: Tax = $%4.2f and Total Purchase = $%4.2f\n\n", (Price*(DelMar/100)), (Price+(Price*(DelMar/100))) );
                break;
       case 2 : printf ("\nEncinitas 2: Tax = $%4.2f and Total Purchase = $%4.2f\n\n", (Price*(Encinitas/100)), (Price+(Price*(Encinitas/100))) );
                break;
       case 3 : printf ("\nLaJolla 3: Tax = $%4.2f and Total Purchase = $%4.2f\n\n", (Price*(LaJolla/100)), (Price+(Price*(LaJolla/100))) );        
                break;
       default : printf( " Error: you must enter an integer 1-3");
      
       }




Then push the thankyou button if you found this helpful biggrin.gif

This post has been edited by yunusabd: 7 Jan, 2009 - 07:54 PM
User is offlineProfile CardPM
+Quote Post

yunusabd
RE: Tax Program Using Miracle C
7 Jan, 2009 - 08:02 PM
Post #5

D.I.C Head
**

Joined: 25 Oct, 2008
Posts: 66



Thanked: 1 times
My Contributions
What are the required parts of you assignment?
If user input for the initial price is not required then just initialize the Price up in your declarations like this

Price = 125.0;


User is offlineProfile CardPM
+Quote Post

matthew180
RE: Tax Program Using Miracle C
7 Jan, 2009 - 10:52 PM
Post #6

D.I.C Head
Group Icon

Joined: 7 Jan, 2009
Posts: 191



Thanked: 31 times
Dream Kudos: 25
My Contributions
Floating point numbers are not designed for precision and should not be used for money math (for example 0.1 cannot be stored in binary floating point). You should use BCD, track cents instead of dollar amounts, or use an arbitrary precision arithmetic lib like GNU MP Bignum.

Matthew

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic

Time is now: 7/4/09 07:02PM

Live C++ Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month