Thread: make an if statement...

  1. #1
    ComSci newbie...ICS kid
    Join Date
    Jul 2006
    Location
    PHILIPPINES!!!
    Posts
    38

    make an if statement...

    i have a problem!
    i want to ask for 5 numbers but when i execute, it asks for 6!! what happened here?
    is this correct?
    main()
    {
    Int x=0;
    int x1=0;
    int x2=0;
    int x3=0;
    int x4=0;
    scanf("%d\n",&x)
    and so on and so forth with the scanning...
    printf("%d,%d,%d,%d,%d",x,x1,x2,x3,x4,);
    }
    is it correct??????

  2. #2
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Code tags and less ???????.

    Post the real full code.

  3. #3
    ComSci newbie...ICS kid
    Join Date
    Jul 2006
    Location
    PHILIPPINES!!!
    Posts
    38
    what real full code????

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Code:
    main()
    {
    Int x=0;
    int x1=0;
    int x2=0;
    int x3=0;
    int x4=0;
    scanf("%d\n",&x)
    and so on and so forth with the scanning...
    printf("%d,%d,%d,%d,%d",x,x1,x2,x3,x4,);
    }
    PC-lint for C/C++ (NT) Vers. 8.00u, Copyright Gimpel Software 1985-2006

    --- Module: testpp.cpp (C++)
    testpp.cpp 3 error [Error 40] Undeclared identifier 'Int'
    testpp.cpp 3 error [Warning 522] Expected void type, assignment, increment or decrement
    testpp.cpp 3 error [Error 10] Expecting ';'
    testpp.cpp 8 error [Error 40] Undeclared identifier 'x'
    testpp.cpp 8 error [Error 1055] Symbol 'scanf' undeclared, assumed to return int
    testpp.cpp 8 error [Info 746] call to function 'scanf()' not made in the presence of a prototype
    testpp.cpp 8 error [Error 40] Undeclared identifier 'x'
    testpp.cpp 9 error [Error 10] Expecting ';'
    testpp.cpp 11 error [Warning 533] function 'main(void)' should return a value (see line 1)
    testpp.cpp 11 error [Warning 529] Symbol 'x1' (line 4) not subsequently referenced
    testpp.cpp 11 error [Warning 529] Symbol 'x2' (line 5) not subsequently referenced
    testpp.cpp 11 error [Warning 529] Symbol 'x3' (line 6) not subsequently referenced
    testpp.cpp 11 error [Warning 529] Symbol 'x4' (line 7) not subsequently referenced

    --- Global Wrap-up

    testpp.cpp 8 error [Warning 526] Symbol 'scanf()' (line 8, file testpp.cpp) not defined
    testpp.cpp 8 error [Warning 628] no argument information provided for function 'scanf()' (line 8, file testpp.cpp)
    Outputting to file testpp.lob
    c:\progra~1\borland\bcc55\bin\bcc32 -c @MAKE0004.@@@
    Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
    testpp.cpp:
    Error E2451 testpp.cpp 3: Undefined symbol 'Int' in function main()
    Error E2379 testpp.cpp 3: Statement missing ; in function main()
    Error E2268 testpp.cpp 8: Call to undefined function 'scanf' in function main()
    Error E2451 testpp.cpp 8: Undefined symbol 'x' in function main()
    Error E2379 testpp.cpp 9: Statement missing ; in function main()
    Warning W8004 testpp.cpp 11: 'x4' is assigned a value that is never used in function main()
    Warning W8004 testpp.cpp 11: 'x3' is assigned a value that is never used in function main()
    Warning W8004 testpp.cpp 11: 'x2' is assigned a value that is never used in function main()
    Warning W8004 testpp.cpp 11: 'x1' is assigned a value that is never used in function main()
    *** 5 errors in Compile ***
    If this isn't similar to what you see, post exactly what you have.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    [sarcasm @ nesir]

    WOW!!!!!! OMFG Dave_Sinkula!!! I never knew that

    Code:
    and so on and so forth with the scanning...
    isn't actually code!!!!!!

    That's so crazy amazing! What have I been doing all this time!!!
    [/sarcasm]

    >>what real full code????

    Exactly, cos I'll bet you haven't lifted a finger and written any code into a file and compiled
    it yet!!! Real full code would typically be what you have been working on yourself, saved
    in a file, that either compiles and doesn't run the way you want, or doesn't compile and
    gives you an error message. Your posted code doesn't meet these conditions because
    you clearly just typed it into the new post box, and badly might I add.

    EDIT: You should also use a thread title that's relevant to your question - you're code
    doesn't have an if statement, nor do you ask how to use one.
    Last edited by Richie T; 07-23-2006 at 09:01 PM.
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  6. #6
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Richie and Dave are my heroes!

  7. #7
    Registered User
    Join Date
    Jul 2006
    Posts
    111
    Alright I am also sort of new to programming so I had a crack at it, and the solution is quite simple. I am guessing that your full code is:
    Code:
    main()
    {
    Int x=0;
    int x1=0;
    int x2=0;
    int x3=0;
    int x4=0;
    scanf("%d\n",&x);
    scanf("%d\n",&x1);
    scanf("%d\n",&x2);
    scanf("%d\n",&x3);
    scanf("%d\n",&x4);
    printf("%d,%d,%d,%d,%d",x,x1,x2,x3,x4,);
    }
    There is nothing wrong with your code, it is doing exactly as you are telling it to do. On line 12 you have:
    Code:
    scanf("%d\n", &x4);
    when you tell it to go to a new line, it requires a value to continue. So if you change line 12 to:
    Code:
    scanf("%d",&x4)
    As you can see "\n" has been removed. This solves the problem you were having.

    Hope I was of some help.

    **EDIT: woops sorry, I rarely make that mistake***
    Last edited by lilrayray; 07-23-2006 at 08:49 PM.

  8. #8
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by lilrayray
    Alright I am also sort of new to programming so I had a crack at it, and the solution is quite simple. I am guessing that your full code is:
    Code:
    main()
    {
    Int x=0;
    int x1=0;
    int x2=0;
    int x3=0;
    int x4=0;
    scanf("%d\n",&x)
    scanf("%d\n",&x1)
    scanf("%d\n",&x2)
    scanf("%d\n",&x3)
    scanf("%d\n",&x4)
    printf("%d,%d,%d,%d,%d",x,x1,x2,x3,x4,);
    }
    There is nothing wrong with your code
    Semicolons would be nice. And then there's this.

    Again, the actual code would be most beneficial.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  9. #9
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Heh, should have left it alone Dave, if the person just wants free code, then we should let him have it, flaws or not.

  10. #10
    Registered User
    Join Date
    Jul 2006
    Posts
    111
    Also, as you learn to program larger programs, you might think about condensing your code. For instance, your code can be condensed from 13 to 3. Here is this:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[])
    {
      int x,x1,x2,x3,x4;
      scanf("%d\n%d\n%d\n%d\n%d", &x,&x1,&x2,&x3,&x4);
      printf("%d%d%d%d%d", x, x1, x2, x3, x4);
      system("PAUSE");	
      return 0;
    }

  11. #11
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    lilrayray: Have you toured our seldom-visitied FAQ?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  12. #12
    Registered User
    Join Date
    Jul 2006
    Posts
    111
    Hey guys, dont be so critical, give him some help. After all, we arent all super programmers with years of experience, ease up.

  13. #13
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    Well actually lilrayray, there's quite a bit wrong with nesir's code, as indicated
    by Dave's post. I'd suggest that you read your own post again, since there are
    a good few errors and inconsistencies that you left out:

    Code:
    Int x=0; /*capital i?*/
    int x1=0; /*lower case i!!!*/
    
    .
    .
    .
    scanf("%d\n",&x);
    scanf("%d\n",&x1);
    scanf("%d\n",&x1); /*missing semicolons, inconsistant sequence of scanfs*/
    some advice to nesir: if you find youself creating variables called x,x1,x2...
    you probably need an array, but I doubt you've used them before since last
    week you didn't know how to use a while loop.

    I'm genuinely not trying to sound cranky in this post (in the last one I was ),
    I'm just trying to clarify a couple of things for people.

    >>Richie and Dave are my heroes!

    Does that make me a role model??? I don't handle responsibility well!

    EDIT: DAMMIT i type slowly!!!

    EDIT 2:

    >>Hey guys, dont be so critical, give him some help.

    That's what I'd like to do, but he's not giving us much of an opportunity to do so
    because he hasn't shown much initiative so far. Both nesir and tatsume joined
    the board last week asking people for a program to print put the even numbers
    between 2 and 18. These guys are just looking for someone to do all their work
    for them. Personally I think that type of person should be ***insert vulgar action***
    but alas the world is full of them, and people like me would have nobody left to
    make me feel smart!
    Last edited by Richie T; 07-23-2006 at 08:59 PM.
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  14. #14
    Registered User
    Join Date
    Jul 2006
    Posts
    111
    I have been to the FAQ. What is it you just must have me see?

  15. #15
    Registered User
    Join Date
    Jul 2006
    Posts
    111
    Srry everyone, it is late, dont listen to my posts, I think I have patched them up, if not, tell me. I am just trying to help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 05:19 AM
  2. HELP!wanting to make full screen game windowed
    By rented in forum Game Programming
    Replies: 3
    Last Post: 06-11-2004, 04:19 AM
  3. make all rule
    By duffy in forum C Programming
    Replies: 9
    Last Post: 09-11-2003, 01:05 PM
  4. Question about atheists
    By gcn_zelda in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 08-11-2003, 11:50 AM
  5. 'functions' in make?
    By mart_man00 in forum C Programming
    Replies: 1
    Last Post: 06-21-2003, 02:16 PM