Help on a code problem

This is a discussion on Help on a code problem within the C Programming forums, part of the General Programming Boards category; Well, i got this when i try to compile this piece of code: Code: #include <stdio.h> void main() { int ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    18

    Help on a code problem

    Well, i got this when i try to compile this piece of code:
    Code:
    #include <stdio.h>
    
    void main()
    {
         int first,second;
         printf("please enter the first number: ");
         scanf("%d", &first);
         printf("please enter the second number: ");
         scanf("%d", &second);
         printf("The sum of the numbers is %d\n",
                                     first+second);
    }
    I currently use Dev-CPP, and i tryed it on a friend's Visual C++, almost same results.


    P:S
    What is the best IDE and compiler to use for learning C? (Cost is unimportant)
    Last edited by Denisius; 01-04-2007 at 06:28 AM.

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    What exactly is the problem
    except void main instead of int main()
    this code has no problems.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    18

    N/A

    The problem is that after i put in the second number, the program just closes itself.
    Without showing the output.

    Also, do you think Visual C++ 6.0 is suitable for beginner's learning?

  4. #4
    Registered User Arminel's Avatar
    Join Date
    Dec 2006
    Location
    Giurgiu
    Posts
    6
    Add #include <stdlib.h>

    and just before return 0; add a system("PAUSE");

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    system is not so portable...
    you can read FAQ http://faq.cprogramming.com/cgi-bin/...&id=1043284385

    In my opinion - VC6 is goog enough, maybe a little bit old and not fully standard compliant.
    You can look at the VC 2005 Express that is free, more standard compliant and should inherit all the good features of the VC6... i cannot be sure on the last statement because I'm still using mostly the VC6
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  6. #6
    Registered User
    Join Date
    Jan 2007
    Posts
    18
    Last edited by Denisius; 01-04-2007 at 07:20 AM.

  7. #7
    Registered User
    Join Date
    Nov 2006
    Posts
    65
    I would put money that you didn't save the file as .c and you have it on default .cpp *c++ file*. Thats why it wont work. Also use Dev C++ IDE on bloodshed.net, I have been using it for a while and find it to be to quality but then again after ANSI C was produced and such standard was set. All compliers that say there ANSI supported then will all run the same way, thus its the setting on the IDE and the apearence of the IDE you should look for. Find what you work best with. Back to your code, why did you void main()? Sounds like overkill.
    You rant and rave about it, but at the end of the day, it doesn't matter if people use it as long as you don't see.
    People are free to read the arguments, but if the only way for you to discover gravity is by jumping off a cliff, then that is what you're going to have to experience for yourself.
    Eventually, this "fast and loose" approach of yours will bite you one too many times, then you'll figure out the correct way to do things. - Salem

  8. #8
    Registered User
    Join Date
    Jan 2007
    Posts
    18
    Well, i managed to get it to work on Visual C++, due to the help of Vart and Arminel(Thanks )
    But on Dev-C++ i still keep getting this error(View the Screenshot above). But i guess that's already a problem with the Dev-C++ client, anyway, thanks again for the quick help.

  9. #9
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    There is no void main. It should be int main. Always.

    Also, instead of system("PAUSE"), which is non-portable, I would use getchar(), which is portable.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  10. #10
    Registered User
    Join Date
    Nov 2006
    Posts
    65
    I complied this with ease in Dev C++ ver 4.9.9.2. Maybe you have not have it set in C. Try saving it as a .C file then try. I cant see you error I am at school so I am just guessing.
    You rant and rave about it, but at the end of the day, it doesn't matter if people use it as long as you don't see.
    People are free to read the arguments, but if the only way for you to discover gravity is by jumping off a cliff, then that is what you're going to have to experience for yourself.
    Eventually, this "fast and loose" approach of yours will bite you one too many times, then you'll figure out the correct way to do things. - Salem

  11. #11
    Registered User
    Join Date
    Jan 2007
    Posts
    18
    It's ok, i have bought Visual C++.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code problem
    By sybariticak47 in forum C++ Programming
    Replies: 9
    Last Post: 02-28-2006, 10:50 AM
  2. Problem with game code.
    By ajdspud in forum C++ Programming
    Replies: 5
    Last Post: 02-14-2006, 05:39 PM
  3. problem with selection code
    By DavidP in forum Game Programming
    Replies: 1
    Last Post: 06-14-2004, 01:05 PM
  4. Replies: 5
    Last Post: 12-03-2003, 04:47 PM
  5. Help with code for simple Y2K problem
    By Mule in forum C++ Programming
    Replies: 3
    Last Post: 03-05-2003, 11:53 PM

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