• 0

[C] "isdigit" validation problems


Question

Hello! I have a small program which calculates tax. I've got all the requirements down except for one which is racking my brain. I tried using "isdigit" to validate the user input for the menu so entering a letter doesn't make it go nuts but I can't get it to work. I have a "while" loop validating the entry to make sure it's within the range of possible options (1-4), just need to weed out the letters. The code is posted below. Any help would be greatly appreciated!

/******************************************************************
*  Source File Name: Tax Calculator.c				  *
*  Date Final Submmitted: 3/9/09				  *
*								  *
*  Description: 						  *
*  This program takes values assigned to variables and calculates *
*  the tax and for each of the Kudler Fine Foods locales	  *
*  Initial program has all of the values hard coded.		  *
*-----------------------------------------------------------------*
*  Date	Modified by   Description of Change			  *
*  ------  ------------  -----------------------------------------*
*  022309  Change Request #1 to prompt the user for *
*		  the grocery amount, and calculate and display total	  *
*		  sales amount.					  *
*								  *
*  030209  Change Request #2 to add menu selection  *
*		  for Location and display only the tax and total for	  *
*		  that location.					  *
*******************************************************************/

/******************************************************************
*																 *
*  Here are the INCLUDES that are needed						  *
*																 *
*******************************************************************/

#include <stdio.h>
#include <ctype.h>

/******************************************************************
*																 *
*  Here are the Function Prototypes that are needed			   *
*																 *
*******************************************************************/

void getfAmount();
void printTableHeader();
void printLocMenu();
float calcSalesTax(float, float);
float calcTotal(float, float);

/******************************************************************
*  Float variables:			 						*
*  fAmount is the amount of the groceries		 		  *
*  fDelMarTax is the tax rate for DelMar					*
*  fEncinitasTax is the tax rate for Encinitas			  *
*  fLaJollaTax is the tax rate for La Jolla				*
*******************************************************************/

float fAmount=0.00;
int iSelection=0;
int iValidate=0;
float fDelMarTax=7.25;
float fEncinitasTax=7.50;
float fLaJollaTax=7.75;
float fDelTaxTotal=0.00;
float fEncTaxTotal=0.00;
float fLaJTaxTotal=0.00;

main() //Start main function
{

   printf("\t\tKudler Fine Foods\n");
   printf("\t\tTax Calculator\n\n");

   //Location selection menu
   printf("\nLocation Menu\n");
   printf("\n1\tDel Mar");
   printf("\n2\tEncinitas");
   printf("\n3\tLa Jolla");
   printf("\n4\tQuit\n");
   printf("\n\nEnter your selection (1-4): ");
   scanf("%d", &iSelection);	 

//Need verification to weed out letters using isdigit if possible

	  while (iSelection < 1 || iSelection > 4) {   
		 printf("\nPlease enter a valid number (1-4): ");
		 scanf("%d", &iSelection);
	  }

	  if (iSelection == 1) {
		 getfAmount();
		 fDelTaxTotal=calcSalesTax(fAmount, 7.25);
		 printTableHeader();
		 printf("\n\nDel Mar\t\t%.2f\t\t$%.2f\t\t%.2f\n", fDelMarTax, fDelTaxTotal, calcTotal(fAmount, fDelTaxTotal));
	  }

	  if (iSelection == 2) {
		 getfAmount();
		 fEncTaxTotal=calcSalesTax(fAmount, 7.5);
		 printTableHeader();
		 printf("\nEncinitas\t%.2f\t\t$%.2f\t\t%.2f\n", fEncinitasTax, fEncTaxTotal, calcTotal(fAmount, fEncTaxTotal));
	  }

	  if (iSelection == 3) {
		 getfAmount();
		 fLaJTaxTotal=calcSalesTax(fAmount, 7.75);
		 printTableHeader();
		 printf("\nLa Jolla\t%.2f\t\t$%.2f\t\t%.2f\n", fLaJollaTax, fLaJTaxTotal, calcTotal(fAmount, fLaJTaxTotal));
	  }

	  if (iSelection == 4) {
		 printf("\n\n\tThank You.");
	  }

} //End main function

/******************************************************************
*																 *
*  Here are the Function Definitions that are needed			  *
*																 *
*******************************************************************/

void getfAmount()
{

   printf("\n\nEnter the purchase amount: $");
   scanf("%f", &fAmount);

   //While loop for positive number verification
   while ( fAmount <= 0 ) {
	  printf("\nInvalid purchase amount.");
	  printf("\nPlease enter a valid purchase amount: $");
	  scanf("%f", &fAmount);
   } //End while loop

} //End function definition

void printTableHeader()
{

   printf("\n\n\nLocation\tSales Tax\tTax Amount\tTotal Price\n");

} //End function definition

float calcSalesTax(float fAmount, float locTax)
{

   return (fAmount*locTax)/100;

} //End function definition

float calcTotal(float fAmount, float locTotalTax)
{

   return (fAmount+locTotalTax);

} //End function definition

Link to comment
Share on other sites

Recommended Posts

  • 0

you can confine your condition by converting the input into ascii values and checking whether it lies withing the given specified range of numbers

Hope it wll help :)

Link to comment
Share on other sites

  • 0

you can try using atoi

http://www.cplusplus.com/reference/clibrar...tdlib/atoi.html

because i bet your code fails where if its a string!

On success, the function returns the converted integral number as an int value.

If no valid conversion could be performed, a zero value is returned.

If the correct value is out of the range of representable values, INT_MAX or INT_MIN is returned.

so you'll do something like

int menu = atoi(*menu_number)

if(menu)//if(0) is false

{

if(menu == 1)

... etc

}

Link to comment
Share on other sites

  • 0
you can confine your condition by converting the input into ascii values and checking whether it lies withing the given specified range of numbers

Hope it wll help :)

Sounds like it would work. How do I go about doing that? This is for my class so I'm just now learning about it all. :D

Link to comment
Share on other sites

  • 0
Sounds like it would work. How do I go about doing that? This is for my class so I'm just now learning about it all. :D

I dont know much of C++

Please rectify

#include <iostream.h>
#include <stdlib.h>
int main()
{
		int number;
		char letter;
		int option; 

		cout<<"Convert ASCII numbers into characters and vice versa";

		cout<<endl<<"[1] * ASCII -> ABC"

				<<endl<<"[2] * ABC -> ASCII"

				<<endl<<"[3] * EXIT"<<endl;; 

		cin>>option;

		switch (option) //Detects the option

			   {
				case 1:
						cout<<"Enter a number : ";#
						cin >> number; //Inputs the number#
						cout<<"The number you entered is : \""<<char(number)<<"\" in ASCII"<<endl; //Ouputs the same number in char
						break; 

				case 2:
						cout<<"Enter a letter : ";
						cin >> letter; //Inputs the letter
						cout<<"The character you entered is : \""<<int(letter)<<"\" in ASCII"<<endl; //Outputs the same letter in int
						break;

				case 3:
						return 0;
				default: //If user chooses anything else besides options given
						cout<<"Invalid Option!";
						system("PAUSE");
						break;
				} 

		system("PAUSE");
		return 0;

}

You can do that using following code

for more about ascii table and their corresponding values refer this

U can see from there that numeric numbers [single character] will definately have values 48-57

Hope it would help a little :)

Link to comment
Share on other sites

  • 0

You can also do it using cin.ignore(), I can't post the link right now because I'm at Uni but I'll post it later. I was using something identical to this because I only wanted an integer within a specific range from the user, and reject everything else.

edit: if you look on Google, you're looking for input validation

Link to comment
Share on other sites

  • 0

Can't edit my post now. The bookmark I had saved isn't loading so here's the code I use to get my user data

int GetUserData()
{
	bool invalid = true;
	while(invalid == true)
	{
		cin >> input;

		if (cin.fail()){ 
			cin.clear();
			cin.ignore(400, '\n');	// clear the stream
			continue; // try again 
		}

		cin.ignore(400, '\n'); // clear the stream

		// If more than two characters were cleared from the stream
		// input is invalid
		if (cin.gcount() > 1){
			continue;
		}

		// Integer has been provided, now check its range
		if ( << RANGE CHECK YOUR INTEGER HERE >>){
			continue;
		}else{
			// integer is valid
			// Do stuff here
			invalid = false;
		}
	}

	return input;
}

I think its pretty bullet proof for checking you have an integer and it's in the range you're looking for. Hope it helps!

Link to comment
Share on other sites

  • 0

Whoops my bad!! :blush: I'll have a look for something in C!

edit:

How about this? I tested it for character input and sets of characters and it worked fine.

#include <stdio.h>

int main(void)
{
	int number;
	char ch;

	printf("Enter a number between 1-4\n");

	do {
		fflush(stdin);
		printf("Choice: ");
		ch = getchar();
	} while(ch!='1' && ch!='2' && ch!='3' && ch!='4');

	printf("\n");

	number = ch - 48;   // convert ascii number code to its decimal equivalent

	printf("You entered number %d\n", number);

	return 0;
}

The number 48 is used to convert the ASCII code for 1-4 to its decimal equivalent and fflush is used to clear stdin of any excess characters. Hope this helps :)

Edited by ViZioN
Link to comment
Share on other sites

  • 0
Whoops my bad!! :blush: I'll have a look for something in C!

No problem! :woot:

I've tried "isdigit" a few times but it never works. It either always comes out "false" or doesn't work at all. All I want is for user input of letters to no break the program when a user is asked to pick between 1-4. :D

Link to comment
Share on other sites

  • 0

It worked! Thank you!! :D

Just some small editing for it to fit with my code and it did the job.

Edit: Just noticed I can remove the part to check for less than 1 or greater than 4. :)

//Location selection menu
   printf("\nLocation Menu\n");
   printf("\n1\tDel Mar");
   printf("\n2\tEncinitas");
   printf("\n3\tLa Jolla");
   printf("\n4\tQuit\n");

	  do {
		 fflush(stdin);
		 printf("\n\nEnter your selection (1-4): ");
		 ch = getchar();
	  } while(ch!='1' && ch!='2' && ch!='3' && ch!='4');

	  printf("\n");

	  iSelection = ch - 48;   // convert ascii number code to its decimal equivalent

	  while (iSelection < 1 || iSelection > 4) {   
		 printf("\nPlease enter a valid number (1-4): ");
		 scanf("%d", &iSelection);
	  }

	  if (iSelection == 1) {

etc...

Link to comment
Share on other sites

  • 0

Yes you can remove the whole while loop there :) I noticed as well that the code isn't completely bullet proof, it will also accept input where the first digit is 1-4, i.e 113 or 367. It won't crash however. But I think it's still good enough :p

Link to comment
Share on other sites

  • 0

Wow that's weird. I just tried it and you're right, I wonder why that is. :p

I noticed another problem. In my original code posted up top you'll see that I have the user input a price and that's done through a function. However, if you input a letter it breaks it as well. The difference is that it's not a defined range of numbers as the menu but any positive float number. Can the method you gave me for the menu be adapted to work for float numbers so that letters don't break that portion of the code?

I used to hate programming and now this simple program has spiked my curiosity. It's only beginners code! :p

Link to comment
Share on other sites

  • 0

Well if you think what is happening, getchar() is taking a single character from the input stream which could be 3 or 3999993 but it only takes one character. The rest is then cleared by using fflush(). Hence when the character is checked it is valid.

I'm not sure if it could be adapted to work for floating point numbers. I'll have a think and a look around :p

edit: I found this which is a function for converting an ascii string to a floating point number. Don't worry about it saying C++, it is actually C code. The good thing is that, if no valid conversion can be perfomed it returns 0 so you can simply loop till the user provides a float that is valid :)

Something like this?

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

int main ()
{
	double n;
	char szInput [256];
	do{
		printf ( "Enter number:");
		gets ( szInput );
		n = atof ( szInput );

	}while(n == 0);

	printf ( "Value: %f" , n );
	system("PAUSE");

	return 0;
}

Edited by ViZioN
Link to comment
Share on other sites

  • 0
Well if you think what is happening, getchar() is taking a single character from the input stream which could be 3 or 3999993 but it only takes one character. The rest is then cleared by using fflush(). Hence when the character is checked it is valid.

I'm not sure if it could be adapted to work for floating point numbers. I'll have a think and a look around :p

edit: I found this which is a function for converting an ascii string to a floating point number. Don't worry about it saying C++, it is actually C code. The good thing is that, if no valid conversion can be perfomed it returns 0 so you can simply loop till the user provides a float that is valid :)

Something like this?

no point in dealing with floats, ATOI (3rd post) works just fine

Link to comment
Share on other sites

  • 0
no point in dealing with floats, ATOI (3rd post) works just fine

How come? Money is a float am I not correct? The menu bug was sorted a few posts back. :p

Link to comment
Share on other sites

  • 0
no point in dealing with floats, ATOI (3rd post) works just fine

If he's wanting to enter floating point numbers why use atoi? It will truncate the float which is pointless as the whole reason you are using a float is for the extra precision.

Link to comment
Share on other sites

  • 0
If he's wanting to enter floating point numbers why use atoi? It will truncate the float which is pointless as the whole reason you are using a float is for the extra precision.

I have to use floats with money! :p

Edit: Ok, I modified it for my code but it prints the "Enter the purchase amount: $" statement twice, not sure why. Aside from that it works as it should!

void getfAmount()
{

   do {
	  printf("\n\nEnter the purchase amount: $");
	  gets(szInput);
	  n=atof(szInput);
   } while(n == 0);

} //End function definition

Edited by Crackler
Link to comment
Share on other sites

  • 0
I have to use floats with money! :p

Edit: Ok, I modified it for my code but it prints the "Enter the purchase amount: $" statement twice, not sure why. Aside from that it works as it should!

void getfAmount()
{

   do {
	  printf("\n\nEnter the purchase amount: $");
	  gets(szInput);
	  n=atof(szInput);
   } while(n == 0);

} //End function definition

whoops i guess the problem changed over the past few posts

i thought it was regarding the MENU selection.

sorry lol

Link to comment
Share on other sites

  • 0

I found another bug! It allows the user to enter negative numbers which doesn't exist for money. :p

This simple program is getting worse by the minute, I can just imagine "real" programs. :D

Link to comment
Share on other sites

  • 0
I found another bug! It allows the user to enter negative numbers which doesn't exist for money. :p

Fixed the negative number problem. Using your function code, I don't get the purchase amount statement twice. Can you confirm if you still get it? Easiest solution for the negative number is to change the while condition from == 0 to <= 0

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

void getfAmount();

int main ()
{
	getfAmount();

	system("PAUSE");

	return 0;
}

void getfAmount()
{
   double n;
   char szInput [256];
   do {
	  printf("\n\nEnter the purchase amount: $");
	  gets(szInput);
	  n=atof(szInput);
   } while(n &lt;= 0);

	printf ( "Value: %f" , n );

} //End function definition

This simple program is getting worse by the minute, I can just imagine "real" programs. :D

Input validation is actually a fairly large coding problem. It's quite difficult to make your code bullet proof, and to stop any user from causing buffer overruns etc

Link to comment
Share on other sites

  • 0

I'll post all of the code since I still get the statement twice. The other problem is within the calculations. Wherever "fAmount" is now I have to replace it with either "n" or "szInput" to properly calculate the tax and total, but neither work. :wacko:

BTW. thanks for all the help!!

/******************************************************************
*  Source File Name: Tax Calculator.c				  *
*  Date Final Submmitted: 3/9/09				  *
*								  *
*  Description: 						  *
*  This program takes values assigned to variables and calculates *
*  the tax and for each of the Kudler Fine Foods locales	  *
*  Initial program has all of the values hard coded.		  *
*-----------------------------------------------------------------*
*  Date	Modified by   Description of Change			  *
*  ------  ------------  -----------------------------------------*
*  022309  Change Request #1 to prompt the user for *
*		  the grocery amount, and calculate and display total	  *
*		  sales amount.					  *
*								  *
*  030209  Change Request #2 to add menu selection  *
*		  for Location and display only the tax and total for	  *
*		  that location.					  *
*******************************************************************/

/******************************************************************
*																 *
*  Here are the INCLUDES that are needed						  *
*																 *
*******************************************************************/

#include &lt;stdio.h&gt;
#include &lt;ctype.h&gt;

/******************************************************************
*																 *
*  Here are the Function Prototypes that are needed			   *
*																 *
*******************************************************************/

void getfAmount();
void printTableHeader();
void printLocMenu();
float calcSalesTax(float, float);
float calcTotal(float, float);

/******************************************************************
*  Float variables:			 						*
*  fAmount is the amount of the groceries		 		  *
*  fDelMarTax is the tax rate for DelMar					*
*  fEncinitasTax is the tax rate for Encinitas			  *
*  fLaJollaTax is the tax rate for La Jolla					   *
*  Three float variable for calculated tax amounts	   	  *
*******************************************************************/

float fAmount=0.00;
int iSelection=0;
char ch;
double n;
char szInput [256];
float fDelMarTax=7.25;
float fEncinitasTax=7.50;
float fLaJollaTax=7.75;
float fDelTaxTotal=0.00;
float fEncTaxTotal=0.00;
float fLaJTaxTotal=0.00;

main() //Start main function
{

   printf("\t\tKudler Fine Foods\n");
   printf("\t\tTax Calculator\n\n");

   //Location selection menu
   printf("\nLocation Menu\n");
   printf("\n1\tDel Mar");
   printf("\n2\tEncinitas");
   printf("\n3\tLa Jolla");
   printf("\n4\tQuit\n");

	  do {
		 fflush(stdin);
		 printf("\n\nEnter your selection (1-4): ");
		 ch = getchar();
	  } while(ch!='1' &amp;&amp; ch!='2' &amp;&amp; ch!='3' &amp;&amp; ch!='4');

	  iSelection = ch - 48;   //Convert ascii number code to its decimal equivalent

	  if (iSelection == 1) {
		 getfAmount();
		 fDelTaxTotal=calcSalesTax(fAmount, 7.25);
		 printTableHeader();
		 printf("\n\nDel Mar\t\t%.2f\t\t$%.2f\t\t%.2f\n", fDelMarTax, fDelTaxTotal, calcTotal(fAmount, fDelTaxTotal));
	  }

	  if (iSelection == 2) {
		 getfAmount();
		 fEncTaxTotal=calcSalesTax(fAmount, 7.5);
		 printTableHeader();
		 printf("\nEncinitas\t%.2f\t\t$%.2f\t\t%.2f\n", fEncinitasTax, fEncTaxTotal, calcTotal(fAmount, fEncTaxTotal));
	  }

	  if (iSelection == 3) {
		 getfAmount();
		 fLaJTaxTotal=calcSalesTax(fAmount, 7.75);
		 printTableHeader();
		 printf("\nLa Jolla\t%.2f\t\t$%.2f\t\t%.2f\n", fLaJollaTax, fLaJTaxTotal, calcTotal(fAmount, fLaJTaxTotal));
	  }

	  if (iSelection == 4) {
		 printf("\n\n\tThank You.");
	  }

} //End main function

/******************************************************************
*																 *
*  Here are the Function Definitions that are needed			  *
*																 *
*******************************************************************/

void getfAmount()
{

   do {
	  printf("\n\nEnter the purchase amount: $");
	  gets(szInput);
	  n=atof(szInput);
   } while(n &lt;= 0);

   /*printf("\n\nEnter the purchase amount: $");
   scanf("%f", &amp;fAmount);

   //While loop for positive number verification
   while ( fAmount &lt;= 0 ) {
	  printf("\nInvalid purchase amount.");
	  printf("\nPlease enter a valid purchase amount: $");
	  scanf("%f", &amp;fAmount);
   } //End while loop*/

} //End function definition

void printTableHeader()
{

   printf("\n\n\nLocation\tSales Tax\tTax Amount\tTotal Price\n");

} //End function definition

float calcSalesTax(float fAmount, float locTax)
{

   return (fAmount*locTax)/100;

} //End function definition

float calcTotal(float fAmount, float locTotalTax)
{

   return (fAmount+locTotalTax);

} //End function definition

Link to comment
Share on other sites

  • 0

Think it's all working now ;)

Didn't really change much. For some reason you had nothing before your main() so I made it an int. Didn't want to compile for me otherwise. Fixed the double message to. It was due to where I had the fflush(stdin). I moved it after the getchar() and the double statement stopped occuring. Not entirely sure why. Then I fixed why your tax wasn't working. Your getfAmount() function is void, i.e it doesn't return anything, so whatever input you get from the user, is never returned from the function. And I moved n and szInput into your getfAmount() into the function so they're now local variables to the function. There's no need for them to be global.

It's now:

float getfAmount()

so it returns the user entered data.

Finally I set this value to your float fAmount variable so you can use it elsewhere in the program.

Full code:

/******************************************************************
*  Source File Name: Tax Calculator.c				  *
*  Date Final Submmitted: 3/9/09				  *
*								  *
*  Description:						   *
*  This program takes values assigned to variables and calculates *
*  the tax and for each of the Kudler Fine Foods locales	  *
*  Initial program has all of the values hard coded.		  *
*-----------------------------------------------------------------*
*  Date	Modified by   Description of Change			  *
*  ------  ------------  -----------------------------------------*
*  022309  Change Request #1 to prompt the user for *
*		  the grocery amount, and calculate and display total	  *
*		  sales amount.					  *
*								  *
*  030209  Change Request #2 to add menu selection  *
*		  for Location and display only the tax and total for	  *
*		  that location.					  *
*******************************************************************/

/******************************************************************
*																 *
*  Here are the INCLUDES that are needed						  *
*																 *
*******************************************************************/

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;ctype.h&gt;

/******************************************************************
*																 *
*  Here are the Function Prototypes that are needed			   *
*																 *
*******************************************************************/

float getfAmount();
void printTableHeader();
void printLocMenu();
float calcSalesTax(float, float);
float calcTotal(float, float);

/******************************************************************
*  Float variables:									 *
*  fAmount is the amount of the groceries				   *
*  fDelMarTax is the tax rate for DelMar					*
*  fEncinitasTax is the tax rate for Encinitas			  *
*  fLaJollaTax is the tax rate for La Jolla					   *
*  Three float variable for calculated tax amounts			 *
*******************************************************************/

float fAmount=0.00;
int iSelection=0;
char ch;
float fDelMarTax=7.25;
float fEncinitasTax=7.50;
float fLaJollaTax=7.75;
float fDelTaxTotal=0.00;
float fEncTaxTotal=0.00;
float fLaJTaxTotal=0.00;

int main() //Start main function
{
	printf("\t\tKudler Fine Foods\n");
	printf("\t\tTax Calculator\n\n");

	//Location selection menu
	printf("\nLocation Menu\n");
	printf("\n1\tDel Mar");
	printf("\n2\tEncinitas");
	printf("\n3\tLa Jolla");
	printf("\n4\tQuit\n");

	  do {
			printf("\n\nEnter your selection (1-4): ");
			ch = getchar();
			fflush(stdin);
	  } while(ch!='1' &amp;&amp; ch!='2' &amp;&amp; ch!='3' &amp;&amp; ch!='4');

	  iSelection = ch - 48;   //Convert ascii number code to its decimal equivalent

	  if (iSelection == 1) {
		 fAmount = getfAmount();
		 fDelTaxTotal=calcSalesTax(fAmount, 7.25);
		 printTableHeader();
		 printf("\n\nDel Mar\t\t%.2f\t\t$%.2f\t\t%.2f\n", fDelMarTax, fDelTaxTotal, calcTotal(fAmount, fDelTaxTotal));
	  }

	  if (iSelection == 2) {
		 fAmount = getfAmount();
		 fEncTaxTotal=calcSalesTax(fAmount, 7.5);
		 printTableHeader();
		 printf("\nEncinitas\t%.2f\t\t$%.2f\t\t%.2f\n", fEncinitasTax, fEncTaxTotal, calcTotal(fAmount, fEncTaxTotal));
	  }

	  if (iSelection == 3) {
		 fAmount = getfAmount();
		 fLaJTaxTotal=calcSalesTax(fAmount, 7.75);
		 printTableHeader();
		 printf("\nLa Jolla\t%.2f\t\t$%.2f\t\t%.2f\n", fLaJollaTax, fLaJTaxTotal, calcTotal(fAmount, fLaJTaxTotal));
	  }

	  if (iSelection == 4) {
		 printf("\n\n\tThank You.");
	  }

	system("PAUSE");
	return 0;

} //End main function

/******************************************************************
*																 *
*  Here are the Function Definitions that are needed			  *
*																 *
*******************************************************************/

float getfAmount()
{
	double n;
	char szInput [256];
	do {
		printf("\n\nEnter the purchase amount: $");
		gets(szInput);
		n=atof(szInput);
   } while(n &lt;= 0);


	return n;
   /*printf("\n\nEnter the purchase amount: $");
   scanf("%f", &amp;fAmount);

   //While loop for positive number verification
   while ( fAmount &lt;= 0 ) {
	  printf("\nInvalid purchase amount.");
	  printf("\nPlease enter a valid purchase amount: $");
	  scanf("%f", &amp;fAmount);
   } //End while loop*/

} //End function definition

void printTableHeader()
{

   printf("\n\n\nLocation\tSales Tax\tTax Amount\tTotal Price\n");

} //End function definition

float calcSalesTax(float fAmount, float locTax)
{

   return (fAmount*locTax)/100;

} //End function definition

float calcTotal(float fAmount, float locTotalTax)
{

   return (fAmount+locTotalTax);

} //End function definition

Link to comment
Share on other sites

  • 0

I think it's the compiler that's different. It compiles just fine for me as I posted it without the int before main, etc. I hand edited my code to incorporate the fixes you came up with and it works perfectly. :D

Thanks a million!!!!

Link to comment
Share on other sites

  • 0
I think it's the compiler that's different. It compiles just fine for me as I posted it without the int before main, etc. I hand edited my code to incorporate the fixes you came up with and it works perfectly. :D

Thanks a million!!!!

Well thanks to vizion!!! he made up

was sleeping (bcoz of time line difference) whn u were busy coding :)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.