Thread: need assistance

  1. #16
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    You didn't say what errors/warning you received!!
    Next time include it in your post if there are any.

  2. #17
    Unregistered
    Guest
    ohh hehe sorry but can you still tell me why i needed to add the conio header file for future ref

  3. #18
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Well, when you use 'getch()' or 'getche()' and many other functions, you'll need to include 'conio.h' in your code.


    Analogy:
    I can't know/understand how an engine works unless i have a maunual to explain it to me.


    In the same way, your compiler can't use 'getche()' unless you
    tell it what it is and how it works. All that stuff is in 'conio.h', so you just include it in your code.

  4. #19
    Unregistered
    Guest

    Talking

    thank you, your reply is understood..

  5. #20
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    As your new at this (unreg), I think I need to point out that conio.h is a non-standard library. This, in short, means that it is not guaranteed to exist on all compilers, and actually, there's a lot that it doesn't.

    By using getche(), you are restricting your code to compile under certain compilers only.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #21
    Unregistered
    Guest
    Thought I would send an answer to your original post, though as you said 'goto' should not be used.

    Code:
    #include <stdio.h>
    #include <math.h>
    #include <conio.h>
    
    int main()
    {
       int x,y;
       char o,n;
       char ch;
     
       startover:
      
       printf("What do you want to do?\n");
       printf("ADD, SUBTRACT, MULTIPLY OR DEVIDE\n");
       printf("Enter the first letter\n");
       ch = getchar();
        
       printf("Please enter your value\n");
       scanf("%d",&x);
       printf("Please enter your second value\n");
       scanf("%d",&y);
         
        if (ch == 'a') printf("The value is %d\n",x+y);
        if (ch == 'd') printf("The value is %d\n",x/y);
        if (ch == 'm') printf("The value is %d\n",x*y);
        if (ch == 's') printf("The value is %d\n",x-y);
             
        printf("Would you like to go again?\n");
        printf("Press ENTER to go again\n");
        printf("\n");
    
        rewind(stdin);
        o = getch();
              
        if (o == '\r') goto startover;
              
    }
    No doubt there may be some reason that rewind(); shouldn't be used, but for this example it works.
    Can't see what 'math.h' is needed for.
    getch() returns an int of the ASCII value of a key pressed on the keyboard but does not put it to the screen.
    o is a char
    so you could make o of type int and test for the ASCII value. ie '\r' would be 13.
    so
    int o;

    if(o == 13) goto startover;

    Hope this is useful
    Dav

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hello,i need assistance in completing the code
    By toader in forum C++ Programming
    Replies: 1
    Last Post: 06-22-2009, 03:32 AM
  2. Variable Timer assistance
    By rich2852 in forum C Programming
    Replies: 2
    Last Post: 01-21-2009, 05:43 AM
  3. Any assistance would be greatly appreciated
    By iiwhitexb0iii in forum C Programming
    Replies: 18
    Last Post: 02-26-2006, 12:06 PM
  4. Need some more assistance
    By Thantos in forum Windows Programming
    Replies: 6
    Last Post: 08-14-2003, 12:13 PM
  5. Need assistance for major text base Arena RPG project
    By Ruflano in forum C++ Programming
    Replies: 0
    Last Post: 04-04-2002, 11:11 AM