My first C++ program

Im new to C++ and want to write a quick little program. What I want it to do is ask for two numbers, then it will multiply the two numbers. If the number is greater than 9000, the program will close, but if it is less than 9000, I want it to display the answer. Here is what I have:

#include "stdafx.h"


#include <iostream>

using namespace std;

int main ()
{
double diabeetus1 = 0.0;
double diabeetus2 = 0.0;
double diabeetusavg = (diabeetus1 * diabeetus2);
cout << "Enter First Number";
cin >> diabeetus1;
cout << "Enter the second number";
cin >> diabeetus2;
if ( diabeetusavg > 9000 )
{
cout<<("Thats over 9,000! This program will now terminate");
}
else if ( diabeetusavg < 9000 )
{
cout<<(diabeetus1 * diabeetus2);
}
system("pause");
return 0;
}

For some reason, it doesnt do exactly what I want and skips my if than statement.
Last edited on
You can't bake the cake before you mix the ingredients.

You have to ask for the user input before you attempt to multiply the numbers.
Idd, just move the the intitialization of diabeetusavg below the two input values, and it should run fine. otherwise you multiply 0 with 0, and will always get the same outcome, regardless of input.

Here is my modifed version of your code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

using namespace std;

int main ()
{
	double diabeetus1 = 0.0;
	double diabeetus2 = 0.0;

	cout << "Enter First Number" << endl;
	cin >> diabeetus1;
	cout << "Enter the second number" << endl;
	cin >> diabeetus2;
	double diabeetusavg = (diabeetus1 * diabeetus2);

	if ( diabeetusavg > 9000 )
	cout<<("Thats over 9,000! This program will now terminate") << endl;

	if ( diabeetusavg < 9000 )
	cout << diabeetusavg << endl;


}
Last edited on
Topic archived. No new replies allowed.