Extremely basic program wont work

Jul 22, 2011 at 7:12pm
I'm a newb at C++, I just started today, and I know my program is coded right because I followed a tutorial and I checked like 50 times, and for some reason, my program compiles fine, but when I run it, all it says is: "Press any button to continue" (Which I assume is from system"pause") and it doesn't show any of the other stuff I put! Please help!
Last edited on Jul 22, 2011 at 7:12pm
Jul 22, 2011 at 7:18pm
Not sure how you expect us to help without seeing your code...post your code, in code tags.
Last edited on Jul 22, 2011 at 7:19pm
Jul 22, 2011 at 7:24pm
Like this? Oh and remember, this is like the second most basic program out there
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 #include <windows.h>
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;

int main()
{
    int A = 5;
    int B = 10;
    int C = A + B;
    cout << C << endl;
    
    
  system("pause");
}
  
Jul 22, 2011 at 7:32pm
There's nothing wrong with the code, is this the first program you've made? Must be something wrong with your compiler I'd guess, what compiler are you using?
Jul 22, 2011 at 7:34pm
Other than "Hello, world!", this is my first program, and I'm using Dev C++
EDIT: Hello world worked fine by the way
Last edited on Jul 22, 2011 at 7:34pm
Jul 22, 2011 at 7:58pm
I'm trying reinstalling Dev C++ to see if that helps.
EDIT:
Okay, that fixed it.
Last edited on Jul 22, 2011 at 8:05pm
Jul 22, 2011 at 8:04pm
well, other users on this site seem to think using system("pause") is a bad idea. maybe try it without that? and also to save you some flak from others :P

edit: and add return 0. you need it in main; I don't have a good explanation though
Last edited on Jul 22, 2011 at 8:05pm
Jul 22, 2011 at 8:06pm
Don't use Dev-C++ it's terrible. I use visual studio 2010 express, a lot of people love CodeBlocks and for good reason. Try one of those.
Jul 22, 2011 at 8:08pm
I tried to try visual studio 2010 express, but I couldn't figure out how to download it. I went to the site, but I didn't see any link anywhere. And why is Dev c++ terrible?
Jul 22, 2011 at 8:27pm
Jul 22, 2011 at 8:32pm
Okay, for me, that's a good enough reason to visual studio 2010 express. I thank you for that.
Jul 22, 2011 at 11:23pm
Don't include headers that you don't need. You're not using anything from windows.h or cmath so they shouldn't be included. This is one of my pet hates of programmers brought up on visual studio.
Topic archived. No new replies allowed.