Clearing the screen joking :)

This is a discussion on Clearing the screen joking :) within the C Programming forums, part of the General Programming Boards category; I am writing a C program for a vending machine and I display the drink types and prices then prompt ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    8

    Talking Clearing the screen joking :)

    I am writing a C program for a vending machine and I display the drink types and prices then prompt the user to input a coin (integer) then repeat until they enter '0'. After each coin is inserted the credit must be displayed on screen.

    What I was wondering was if there is a way of placing the cursor up a few lines or clear PART of the screen so that I don't have something like this:

    Insert coin: 10
    Credit: 10
    Insert coin: 5
    Credit 15
    Insert coin: _

    etc etc

    I know I could just clear the screen before each insert but I want the prices displayed all the time.

    I cannot find anything on it in my books or in the documentation of the compiler...I would greatly appreciate any help

    btw Don't flame me for asking how to clear the screen because it's not a straight forward clear
    oh yeah and I'm using Turbo C.

  2. #2
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,156
    Well, using Turbo C you might be able to use the old ANSI Escape Sequences
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    8
    the page is unavailable

  4. #4

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    3

    Re: Clearing the screen joking :)

    Originally posted by marell
    I know I could just clear the screen before each insert but I want the prices displayed all the time.
    Why not print the required stuff immediately after clearing the screen ? it's just going to happen in a flash..

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    8

    Re: Re: Clearing the screen joking :)

    Originally posted by nymph
    Why not print the required stuff immediately after clearing the screen ? it's just going to happen in a flash..
    I know I could just do that but it's for an assignment so I was hoping there was a less wasteful way of doing it, you know what tutors are like

  7. #7
    Registered User
    Join Date
    Mar 2004
    Posts
    8
    So how would I incorporate this - ESC[#A - into my code:

    Code:
     
     #include <stdio.h>
    
     void initialise(void);
     void process_drink(void);
     void dispense_change(void);
    
     int credit, code, coin, cost;
    
    /***** FUNCTION 0 *************************************************/
     main()
     {
    	system ("cls");
    	initialise();
    	process_drink();
    	dispense_change();
    	return 0;
     }
    
    /***** FUNCTION 1 *************************************************/
     void initialise(void)
     {
    	credit = 0;
     }
    
    /***** FUNCTION 2 *************************************************/
     void process_drink(void)
     {
    /** DISPLAY DRINK TYPES **/
    
    	printf("Available drinks:");
    	printf("\n\nCoffee Black          - 100  45p");
    	  printf("\nCoffee Black & Sugar  - 101  45p");
      	  printf("\nCoffee White          - 110  45p");
    	  printf("\nCoffee White & Sugar  - 111  45p");
    	printf("\n\nTea                   - 200  45p");
    	  printf("\nTea & Sugar           - 201  45p");
    	printf("\n\nHot Chocolate         - 300  45p");
    
    /** INPUT COINS **/
    
    	printf("\nAccepted coins: \n5p\n10p\n20p\n50p\n100p\n200p");
    	printf("\nEnter `0' to end coin insertion");
    	printf("\nEnter coin: ");
    	scanf("%d",&coin);
    
    	while(coin != 0)
    	{
    /** VALIDATE COIN **/
    
    		while((coin != 5) && (coin != 10)) 
    		{
    			printf("\nThat coin was invalid!");
    			printf("\nEnter another: ");
    			scanf("%d",&coin);
    		}
    
    		credit = credit + coin;
    
    		system ("cls");
    
    		printf("\n\nCredit: %d",credit);
    
    		printf("\nEnter coin: ");
    		scanf("%d",&coin);
    	}
     }
    
    
    
    
    
    
     void dispense_change(void)
     {
     }

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    It's not portable code, but I think in Turbo C you can use gotoxy().
    Code:
    #include <conio.h>
    .
    .
    gotoxy(x,y);

  9. #9
    Registered User
    Join Date
    Mar 2004
    Posts
    8
    Not portable? So if the screen resolution was different on my tutors PC it would goto a different row?

    Is there afunction that gets the location of the cursor?

  10. #10
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  11. #11
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,156
    Originally posted by marell
    So how would I incorporate this - ESC[#A - into my code
    Code:
    #define  ESC  0x1B
    ...
    printf("%c[#A", ESC);
    is one way to do it.

    Code:
    char *cursorUp = "\x1B[#A";
    ...
    printf("%s", cursorUp);
    is another.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  12. #12
    Registered User
    Join Date
    Mar 2004
    Posts
    8
    Using this code:

    Code:
     #include <stdio.h>
     #define  ESC  0x1B
    
    
     void initialise(void);
     void process_drink(void);
     void dispense_change(void);
    
     int credit, code, coin, cost;
    
    /***** FUNCTION 0 *************************************************/
     main()
     {
    	system ("cls");
    	initialise();
    	process_drink();
    	dispense_change();
    	return 0;
     }
    
    /***** FUNCTION 1 *************************************************/
     void initialise(void)
     {
    	credit = 0;
     }
    
    /***** FUNCTION 2 *************************************************/
     void process_drink(void)
     {
    /** DISPLAY DRINK TYPES **/
    
    	printf("Available drinks:");
    	printf("\n\nCoffee Black          - 100  45p");
    	  printf("\nCoffee Black & Sugar  - 101  45p");
      	  printf("\nCoffee White          - 110  45p");
    	  printf("\nCoffee White & Sugar  - 111  45p");
    	printf("\n\nTea                   - 200  45p");
    	  printf("\nTea & Sugar           - 201  45p");
    	printf("\n\nHot Chocolate         - 300  45p");
    
    /** INPUT COINS **/
    
    	printf("\nAccepted coins: \n5p\n10p\n20p\n50p\n100p\n200p");
    	printf("\nEnter `0' to end coin insertion");
    	printf("\nEnter coin: ");
    	scanf("%d",&coin);
    
    	while(coin != 0)
    	{
    /** VALIDATE COIN **/
    
    		while((coin != 5) && (coin != 10) && (coin != 20) &&
    		(coin != 50) && (coin != 100) && (coin != 200))
    		{
    			printf("\nThat coin was invalid!");
    			printf("\nEnter another: ");
    			scanf("%d",&coin);
    			if(coin == 0)
    			return;
    		}
    
    		credit = credit + coin;
    
    		printf("%c[2A", ESC);
    
    		printf("\n\nCredit: %d",credit);
    
    		printf("\nEnter coin: ");
    		scanf("%d",&coin);
    	}
     }
    
    
    
    
    
    
     void dispense_change(void)
     {
     }
    the only difference made is that
    Code:
     (left arrow)[2A
    is printed. I know I sound like a complete amatuer but plz help

  13. #13
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,156
    Please when posting code that you have a question about, don't post the entire program unless it's relevant. You only need to post the few lines that contain the problem.

    I remember now you need to add
    [code]device=path\ANSI.sys[/quote]
    to your config.sys file to process the ANSI commands. It's in the windows\system32 directory in many of the Windows systems. Replace path above with the appropriate directory
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  14. #14
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    My suggestion would be just to re-print the menu everytime with the updated credit. It's really silly and useless to try and code around it. BTW, your menu could use some extra formatting.

  15. #15
    Registered User
    Join Date
    Mar 2004
    Posts
    8
    Originally posted by WaltP
    I remember now you need to add
    [code]device=path\ANSI.sys
    to your config.sys file to process the ANSI commands. It's in the windows\system32 directory in many of the Windows systems. Replace path above with the appropriate directory
    would this have to be done on every PC that ran the program?

    If it would, I think I will just print the prices each time. After all it's only HNC level

    Anywayz thnx for all the feedback guys

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 03:56 PM
  2. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 09:18 PM
  3. clearing the screen
    By ssharish in forum C Programming
    Replies: 2
    Last Post: 02-01-2005, 08:00 PM
  4. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM
  5. Clearing the screen
    By Shadow in forum C Programming
    Replies: 4
    Last Post: 05-23-2002, 01:40 PM

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