Hi, everyone. I am extremely new to C programming however, I have been programming VB for a few years now. I am stumped why I cannot get my code to work. It is very basic but I do not understand why the while loop executes even when it is false. Can someone help? Thank you in advance.
Code:
#include <stdio.h>
#include<system.h>
#include <ctype.h>
int main(void)
{
//*****Declare Tax, Tax Rate and Purchase Amount variables as double to handle large floating point numbers***********************
double dSlsTaxD, dSlsTaxE, dSlsTaxL, dPurAmt, dSlsTaxRateD, dSlsTaxRateE, dSlsTaxRateL;
//*****Declare user input variable as Integer because choices are 1 or 2**********************************************************
int shouldContinue = 0;
//*****Declare validation variable as Character string that will handle 256 characters**************************************************
char garbage[256];
//********************************************************************************************************************************
//*****Initialize the variables*****
dPurAmt = 0;
dSlsTaxD = 0;
dSlsTaxE = 0;
dSlsTaxL = 0;
dSlsTaxRateD = .0725; // Sales Tax Rate for Del Mar store
dSlsTaxRateE = .0750; // Sales Tax Rate for Encinitas store
dSlsTaxRateL = .0775; // Sales Tax Rate for La Jolla store
//********************************************************************************************************************************
while((shouldContinue == 0));{
printf("\n Please enter Purchase Amount: ");
scanf("%lf", &dPurAmt);
if(scanf("%lf", &dPurAmt) != 1) {
shouldContinue = 0;
gets(garbage);
printf("\nPlease enter a valid dollar amount without commas: ");
scanf("%lf", &dPurAmt); }
else
shouldContinue = 1;
}
//*****Calculate sales tax for individual stores*****
dSlsTaxD = dSlsTaxRateD * dPurAmt;
dSlsTaxE = dSlsTaxRateE * dPurAmt;
dSlsTaxL = dSlsTaxRateL * dPurAmt;
//***********************************************************************************************************************
//*****Print results of calculation to the monitor*****
printf("\n For the purchase amount of $%.2f\n", dPurAmt);
printf("\nThe Del Mar store's sales tax will be: $%.2f", dSlsTaxD);
printf("\nThe Encinitas store's sales tax will be: $%.2f", dSlsTaxE);
printf("\nThe La Jolla store's sales tax will be: $%.2f", dSlsTaxL);
//***********************************************************************************************************************
//*****Forces the DOS prompt window to stay open because it is waiting for a key to be pressed*****
getch();
//*****This line terminates the execution of the main function.*****
return 0;
}