hello i am new to these boards and new to the language of c. i am trying to figure out this user input stuff....and i am about to kill myself! every time i think i have it...C throws me another road block.
i am trying to create a menu based program to calculate sales tax, and i want to be able to check for negative numbers; as well as characters in the user input (sorry if my English is bad). basically i need some big help please. i mean there has to be a way to check for both negative and character based input?
thank you, here is code.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
main()
{ // begin main
//Defining integers, floating points and characters.
float fPrice, fSalesTax_Del, fSalesTax_Enci, fSalesTax_Jolla, fAnswer, fCheckSum;
int iDivide_By, iResponse;
char cMenu;
iResponse = 0;
fCheckSum = 0;
fPrice = 0;
fSalesTax_Del = 7.25;
fSalesTax_Enci = 7.5;
fSalesTax_Jolla = 7.75;
iDivide_By = 100;
fAnswer = 0;
cMenu = iResponse;
while ( fPrice == 0 ) // loop for fPrice, makes sure something is selected
{
cMenu = 0;
while( cMenu == 0 ) // Menu system loop
{
// menu display
printf("\nKudler Fine Foods - Store Selector\n");
printf("\nA\tDel Mar Location\n");
printf("B\tThe Encinitas Location\n");
printf("C\tThe La Jolla Location\n");
printf("\nPlease select a Store: ");
scanf(" %c", &cMenu ); // input for menu selection
// if statment for cMenu and includes lower case
if ((cMenu == 'A' && cMenu == 'a') || (cMenu == 'B' && cMenu == 'b') || (cMenu == 'C' && cMenu == 'c'))
if (cMenu = 1); // statment for if cMenu is true
else
printf("\nInvalid Store Selection.\n");
} //end cMenu while loop
// clear extraneous text
system("clear");
// switch for menu system, launches specialized code for each case
switch ( cMenu ) //begins switch for menu system
{
//case for switch includes lowercase letters for validation
case 'a': case 'A':
printf("\nEnter Purchase Amount For The Del Mar Location:\n $ ");
scanf("%f", &fPrice);
while (fPrice < fCheckSum) { //begin validation loop
printf("\n\tPlease Re-enter your Purchase Amount: $");
scanf("%f", &fPrice);
}//end while loop
fAnswer = fPrice * fSalesTax_Jolla / iDivide_By; // formula to calculate this stores sales tax
printf("\nThe Sales Tax Amount For The Del Mar Location Is $%.2f\n", fAnswer);
printf("\nAnd Total Sales Amount Is $%.2f\n", fPrice);
break;
//case for switch includes lowercase letters for validation
case 'b': case 'B':
printf("\nEnter Purchase Amount For The Encinitas Location:\n $ ");
scanf("%f", &fPrice);
while (fPrice < fCheckSum) { //begin while validation loop
printf("\n\tPlease Re-enter your Purchase Amount: $");
scanf("%f", &fPrice);
}//end while loop
fAnswer = fPrice * fSalesTax_Jolla / iDivide_By; // formula to calculate this stores sales tax
printf("\nThe Sales Tax Amount For The Encinitas Location Is $%.2f\n", fAnswer);
printf("\nAnd Total Sales Amount Is $%.2f\n", fPrice);
break;
//case for switch includes lowercase letters for validation
case 'c': case 'C':
printf("\nEnter Purchase Amount For The La Jolla Location:\n $ ");
scanf("%f", &fPrice);
while (fPrice < fCheckSum) { //begin while validation loop
printf("\n\tPlease Re-enter your Purchase Amount: $");
scanf("%f", &fPrice);
}//end while loop
fAnswer = fPrice * fSalesTax_Jolla / iDivide_By; // formula to calculate this stores sales tax
printf("\nThe Sales Tax Amount For The La Jolla Location Is $%.2f\n", fAnswer);
printf("\nAnd Total Sales Amount Is $%.2f\n", fPrice);
break;
} //end switch
} //end fPrice while loop
printf("\nPress Enter key to end.\n");
getchar();
return 0;
} // end main