End Program

This is a discussion on End Program within the C Programming forums, part of the General Programming Boards category; Can anyone tell me why my program ends if the user inputs an alpha instead starting the loop again? thanks ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    6

    End Program

    Can anyone tell me why my program ends if the user inputs an alpha instead starting the loop again?
    thanks

    Code:
    #include <stdio.h>
    #include <cstdio>
    #include <iostream>
    
    
    main()
    
    {
    
    // variables
        int iResponse, validate;
        float purchaseAmount, tax = 0.0;
        float delMarTaxRate=.0725;
        float encinitasTaxRate=.075;
        float laJollaTaxRate=.0775;
        char option = 'Y';
    
    // Menu Selection
    	do // loop for repeating process
    	{	printf("\n\t\tStore Location\n");
        		printf("\n\t1\tDel Mar\n");
       		printf("\t2\tEncinitas\n");
        		printf("\t3\tLa Jolla\n");
        		printf("\nPlease select a location: ");
        			scanf("%d", &iResponse);
       
    //switch for store location    
    switch (iResponse) 
    		{
    
        		case 1:
            		printf("\nYou selected Del Mar\n\n");
            		break;
        		case 2:
            		printf("You selected Encinitas\n\n");
            		break;
        		case 3:
            		printf("You selected La Jolla\n\n");
            		break;
        		default:
        	       		printf("Invalid selection\n\n");
            		goto skip_point;    
    		} //end switch
    
    // Input sale amount
    	printf("\tEnter Purchase Amount: ");
    	validate =scanf("%f", &purchaseAmount);
               	if (validate!=0); 	
    		else goto skip_point;
    // Display tax and total sale amount	
    		if(iResponse==1)
    		{	printf("\n\tThe tax amount for Del Mar is $%.2f\t", 
                			tax = (purchaseAmount*delMarTaxRate));
            		printf("\n\tThe total sale amount for Del Mar is $%.2f\t\n", 
                			purchaseAmount + (tax + .005));
           		}
             	if(iResponse==2)
            	{	printf("\n\tThe tax amount for Encinitas is $%.2f\t", 
                			tax =(purchaseAmount*encinitasTaxRate));
            		printf("\n\tThe total sale amount for Encinitas is $%.2f\t\n", 
                			purchaseAmount + tax );
           		}
            	if(iResponse==3)
            	{	printf("\n\tThe tax amount for La Jolla is $%.2f\t", 
                			tax = (purchaseAmount*laJollaTaxRate));                 
            		printf("\n\tThe total sale amount for La Jolla is $%.2f\t\n", 
                			purchaseAmount + (tax + .005));
            	}		
    		skip_point:
    				if (validate==0)
    		{
    				printf("\nInvalid purchase amount\n\n");
    		
    				
    				
    			printf("\nTry again? Y/N\t");
    				scanf("%c",&option);
    		}			
    	}								
    			while (option == 'y' || option == 'Y');
    				
    	          
            	printf("\nPress any key to terminate program");
            
    getch();   
      
    }

  2. #2
    Registered User
    Join Date
    Mar 2005
    Posts
    135
    Quote Originally Posted by jhwebster1
    ummm Thanks I guess??? But I do not see anything in your post that was helpful.

    Does anyone have a suggestion and not just a slam?

    thanks
    Using goto is frowned upon because it makes code harder to read (which they call spaghetti code). Also, most noob questions could be answered if they read the FAQ, which also has a word about not using goto. And last but not least, two of the header files your program has shouldn't be in there, if you're programming in C, because they are C++ headers. Where are you learning from? or who's teaching you? Either choose C, or C++, then you won't confuse people trying to help you and you will get helpful answers.


    xeddiex.

  3. #3
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    Posts from this thread were deleted because they did not provide relevent information or provided information in a flaming manner.

    Some of the relevent comments were:

    You seem to be confused between the difference between C and C++
    Most of your code seems to be C, and it is posted on the C forum.

    ....

    Your style makes reading your code difficult
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,069
    Ahhh... but the posts did contain all the information he needed, yet the OP seemed to not see it.

    You have to define main as an int. You can't just put main(), that wouldn't be a definition.

    Code:
    int main() {
    Besides, Kermi, if you didn't notice this. Look at the similarities between the OP's code and the code in this post:
    I need some help !

    I'd say, they're either the same person with two accounts, classmates in the same class doing the same assignment, or someone just blatantly copied someone else's code.
    Sent from my iPadŽ

  5. #5
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    I think most the valueable information has been repeated in more polite terms.

    I would venture to guess that your latter guess is correct. I do hope that they have both read the boards Homework Policy.
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  6. #6
    old man
    Join Date
    Dec 2005
    Posts
    90
    It's also unfortunate that "validate" is tested when it's uninitialized.

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,533
    Why did this C program get moved to the C++ board?
    Why was my comment deleted?

    > Can anyone tell me why my program ends if the user inputs an alpha instead starting the loop again?
    I gave you a list, but rather than paying any attention you decided to .......... about it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help! Placement of nodes in a Linked List
    By lostmyshadow in forum C Programming
    Replies: 6
    Last Post: 12-17-2007, 12:21 PM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. singly linked to doubly linked
    By jsbeckton in forum C Programming
    Replies: 10
    Last Post: 11-06-2005, 06:47 PM
  4. Cant figure out how to end my program
    By Summonerur in forum C Programming
    Replies: 9
    Last Post: 10-11-2004, 10:53 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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