Thread: selection
View Single Post
Old 01-25-2003, 08:23 AM   PM User | #3
maes
Regular Coder

 
Join Date: Jul 2002
Location: Belgium
Posts: 124
Thanks: 0
Thanked 0 Times in 0 Posts
maes is an unknown quantity at this point
Sorry for correcting you, but fflush(stdin) can invoke undefined behaviour you can use while (getchar() != '\n'); instead. void main can also produce undefined behaviour so use int main() and put return 0; at the end of your program
About your program, this might help you a bit
Code:
#include <stdio.h> 
#include <conio.h> 
#include <ctype.h> 

int main()   //allways use int main()
{ 
float Purchase, TaxRate; 
char County; 

clrscr(); 
printf("Amount of purchase? "); 
scanf("%f", &Purchase); 
while (getchar() != '\n'); //clear the inputbuffer
printf("County? "); 
scanf("%c", &County); 

County=toupper(County); //store the upper case value ov County in County for later use

if ( County == 'A') 
{TaxRate = Purchase * 0.07;} 

else 
if((County >='B') && (County <='Z')) 
{TaxRate = Purchase * 0.06;} 
else 
if (isdigit(County)) 
{printf("Invalid Character!");} 

printf("Total Bill: %.2f", TaxRate); 
getch(); 
return 0; //return a value to the OS
}
__________________
If you don't succeed at first, redefine succes

Last edited by maes; 02-03-2003 at 02:58 PM..
maes is offline   Reply With Quote