Thread: sorry guys

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    227

    sorry guys

    im sorry for posting again and again but i really want to learn i sure hope you understand... well anyways im trying alot of diffrent things simple things.. but anyways here is my prob

    when i run this and i type in a it says get out of here
    but then i type in b it also say get out of here
    ggrr i dont see that i am doing something wrong but why it isnt working ggrr damn. i have bad luck today


    #include <stdio.h>
    #include <dos.h>

    int main()
    {
    char b;
    char a;
    printf("Enter a value:");
    scanf("%i",&b,&a);
    if (b>a)
    {
    printf("The value is negative\n");
    return 0;
    }
    else
    {
    printf("get out of here\n");
    return 0;
    }
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > scanf("%i",&b,&a);
    Two problems,
    1. you only scan for 1 integer, yet you seem to be wanting to input 2 integers

    scanf("%i %i",&b,&a);
    perhaps.

    2. a and b are chars, not ints
    int a, b;

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    227
    ok i did that as you can see... but its still dont the same problem


    #include <stdio.h>
    #include <dos.h>

    int main()
    {
    char b;
    char a;
    printf("Enter a value:");
    scanf("%s%s",&b,&a);
    if (b>a)
    {
    printf("The value is negative\n");
    return 0;
    }
    else
    {
    printf("get out of here\n");
    return 0;
    }
    }


    ohh and thanx for the int part i didnt reolize it

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > scanf("%s%s",&b,&a);

    No. "%s" is for strings (arrays of characters). "%c" is for a single character.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    227
    ok i have change it to c but it still the same prob....last time i will post cause i dont want you guys to get mad or anything so im going to stay kool.... heh well thanx

  6. #6
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Here's the code:

    Code:
    #include <stdio.h> 
    #include <dos.h> 
    
    int main() 
    { 
    int a, b; 
     
    printf("Enter a value:"); 
    scanf("%d %d",&b, &a); 
    if (b>a) 
    { 
    printf("The value is negative\n"); 
    return 0; 
    } 
    else 
    { 
    printf("get out of here\n"); 
    return 0; 
    } 
    }
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    if (b>a)
    {
    printf("The value is negative\n");
    This is wrong anyway. What if I enter:

    2 3

    3 is greater than 2, but neither are negative.

    3 2

    3 is greater than 2, still neither are negative.

    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    Registered User
    Join Date
    Dec 2001
    Posts
    227

    Wink

    yes it is but i mean like when i run it i get get out of here. like for example

    a= getout of here
    b= get out of here

    but i want it like this

    a= getout of here
    b= The value is negative

    btw its char a,b; not integras

    thanx

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    But you aren't checking to see if the value is negative. You're just comparing number size. That was my whole point.

    Quzah.
    Hope is the first step on the road to disappointment.

  10. #10
    Registered User
    Join Date
    Dec 2001
    Posts
    227
    ohh damn so ahh how would i fix this to go how i want it. im still trying

  11. #11
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Well, since negative numbers are less than 0, use

    if (a < 0)

    or whatever you're actually trying to do.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hey guys, I'm new!
    By MrDoomMaster in forum C++ Programming
    Replies: 15
    Last Post: 10-31-2003, 05:47 PM
  2. How long have you guys been working with C/C++??
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 08-01-2003, 03:41 PM
  3. Tic Tac Toe -- Can you guys rate this please?
    By Estauns in forum Game Programming
    Replies: 2
    Last Post: 09-15-2001, 10:22 AM
  4. hello guys
    By lupi in forum C++ Programming
    Replies: 4
    Last Post: 09-13-2001, 06:42 AM
  5. hello guys
    By lupi in forum C++ Programming
    Replies: 1
    Last Post: 09-09-2001, 01:00 AM