Are Your Sure You Want To Quit? Help Please

This is a discussion on Are Your Sure You Want To Quit? Help Please within the C Programming forums, part of the General Programming Boards category; i need to write a exit screen on my program, i have one nicely layed out etc.. but i want ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    16

    Red face Are Your Sure You Want To Quit? Help Please

    i need to write a exit screen on my program, i have one nicely layed out etc.. but i want it to ask the users if there sure they wanna quit.

    this is a quick sample of my existing code

    <code>
    void main()
    {
    TitleScreen();
    MainMenu(); /*when number 4 is pressed to goes to the end of the function and gotos the quitscreen function*/

    QuitScreen(); /*this screen askes if ya want to quit if 'Y' is entered then it quits, if not then how do i make it go back to the main menu */
    }
    </code>
    Shizzle Ma 'C' Whizzle's

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You need to use a loop (for or while will do).

    >>void main()
    is wrong, use
    >>int main(void)
    and return 0; at the end.

    ... and read about code tags from the link in my signature
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    16
    this is a bit of my code
    i use a loop in the main menu


    Code:
     */
    
    void main()
    {
    	
    	startscr();
    	titlepage();
    	mainmenu();
                    endscr();
    
    }
    
    /*This is the main menu, this is where the user will choose specific options and sub options*/
    void mainmenu()
    {
    	
    	char pcroption;
    	
    	pcroption = 0;	
    
    	do
    	{
    		clrscr();
    		printf("\n\n\t\t  **************************************************");
    		printf("\n\t\t |  'C' Programming - Assignment 1 - Area Program  |\n");	
    		printf("\t\t  **************************************************");
    		printf("\n\n\t\t   1). The surface area of an enclosed cylinder");
    		printf("\n\n\t\t   2). The volume of material in a hollow sphere");
    		printf("\n\n\t\t   3). The area of a triangle");
    		printf("\n\n\t\t   4). Quit the program");	
    		printf("\n\n\n\t\tEnter the letter of your selection: ");
    		pcroption = getch();	/*Gets a letter, and continues, there is no waiting for enter 
    					key to be pressed*/
    		switch(pcroption)
    		{
    			case '1':	//The surface area of an enclosed cylinder
    				surfacearea();
    				break;
    			case '2':	//The volume of material in a hollow sphere
    				hollowsphere();
    				break;
    			case '3':	//The area of a triangle (there are two options for this)
    				trianglemenu();
    				break;
    			case '4':	//Quit program
    				break;
    			default:
    				printf("\n\n\t....Incorrect Value....");
    				hold();
    		}
    	}while(pcroption!='4');
    }
    
    /*This displays the assignment title page, containing the assignment information*/
    void titlepage()
    {
    	clrscr();
    	printf("\n\t        ----------------------------------------\n");
    	printf("\t\t|     Title Page - 'C' Programming     |\n");
    	printf("\t        ----------------------------------------\n\n");
    	printf("\t\t\t      'C' Programming\n\n\n\n");
    	printf("\t\t\t        Assignment 1\n\n");
    	printf("\t\t   Hand-Out Date: W/B 14th October 2002\n");
    	printf("\t\t Hand-In Date: Monday 25th November 2002\n\n\n\n\n\n\n\n\n\n");
    	printf("\tby Paul Roseby 2002");
    	
    	hold();
    }
    */
    &#91;code]&#91;/code]tagged by Salem
    Shizzle Ma 'C' Whizzle's

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    16

    Unhappy

    sorry still didnt get the code thing right

    Shizzle Ma 'C' Whizzle's

  5. #5
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    See if something like this might help. I modified it a bit to suit my compiler.

    Code:
    #include <stdio.h>
    
    void initMess(void);
    void listOptions(void);
    
    int main(void)
    {
    	initMess();
    	listOptions();
    	
    	printf("\nThe program terminated normally.");
    	
    	return 0;
    }
    
    
    
    void initMess(void)
    {
    	printf("Welcome to my program... blah blah blah.\n\n");
    }
    
    void listOptions(void)
    {
    	int testFlag, input;
    	char choice, trash;
    	
    	testFlag = 0;
    	
    	do
    	{
    		printf("\n1) do this.");
    		printf("\n2) do that.");
    		printf("\n3) how bout this.");
    		printf("\n4) quit if you must.");
    		printf("\n\n--> "); 
    		
    		scanf("%d", &input); 
    		
    		switch(input)
    		{
    			case 1: printf("\nOption 1 selected.\n"); /* do this */
    			        break;
    			
    			case 2: printf("\nOption 2 selected.\n"); /* do that */
    			        break;
    			       
    			case 3: printf("\nOption 3 selected.\n"); /* how bout this */
    			        break;
    			        
    			case 4: printf("\nAre you sure you wanna quit? <y:n> ");
    			 
    			        scanf("%c %c", &trash, &choice);
    			        
    			        if(choice == 'y' || choice == 'Y')
    			           testFlag = 1;
    			        
    			        break;
    		    default: /* whatever */
    		             break;
    		};
    		
    	}while(testFlag == 0);
    }
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 11:43 AM
  2. processes not exiting or quit
    By kryptkat in forum Tech Board
    Replies: 8
    Last Post: 11-13-2006, 12:43 PM
  3. I quit!
    By Luigi in forum C++ Programming
    Replies: 8
    Last Post: 12-03-2002, 09:30 AM
  4. implicit declatation of function 'int toupper(...)'
    By Intimd8r in forum C Programming
    Replies: 3
    Last Post: 10-01-2001, 03:43 PM

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