Problems validating

This is a discussion on Problems validating within the C Programming forums, part of the General Programming Boards category; Hi, everyone. I am extremely new to C programming however, I have been programming VB for a few years now. ...

  1. #1
    Registered User
    Join Date
    May 2008

    Problems validating

    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.

    #include <stdio.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;
        			printf("\nPlease enter a valid dollar amount without commas: ");
        			scanf("%lf", &dPurAmt); }
        		    	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*****   
     //*****This line terminates the execution of the main function.***** 
       return 0; 

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    You have an extra semi-colon on this line:
    while((shouldContinue == 0));{
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 05:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 04:48 PM
  4. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  5. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 08:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21