Here is my code. It is a very simple input two numbers and have them added together. My problem is that when I enter in numbers the output is always some crazy large number.
for instance I input 2 and 2, respectively and I got an output of
-506745 the first time
and then when I run it again I input the same two numbers and it spit out this output: 54114125
I have no idea what is going on. Can anyone help?
#include <iostream>
using namespace std;
int main()
{
int num1;
int num2;
int addNum = num1 + num2;
cout << "Enter a value to be multiplied: \n";
cin >> num1;
cout <<"Enter another value to be multiplied: \n";
cin >> num2;
cout <<"The sum of these two numbers is " << addNum << endl;
You compute addNum BEFORE asking the user for the value of num1 and num2.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Thank you a lot.
I can't believe I made that stupid mistake.
I started learning C++ a while ago and then stopped and started learning Python since it is a powerful and easier language to learn. but now I am about to start taking my first Intro to C++ course online this summer so I am just now getting back into brushing up on everything. So thanks a lot!
also I am very new to this whole forum thing so I will definitely check out that link and make sure to use my code tags next time to make it easier for you guys to read. Thanks again!