Need help with this problem!!

closed account (yR9wb7Xj)
" Write a program that prompts the user to input a number. The program should then output the number and a message saying whether the number is positive, negative or zero." When I run it, it works fine but when I put a number say 0 it says negative, when I re run and input a number say 5 it says error, what am I doing wrong? Please do not judge me if I cannot do this problem, because it's very straight forward in what they are asking for. I'm new to programming and this is my first time ever attempting to solve a problem in c++. Everyone has to start somewhere am I right? I've tried multiple times but I'm not getting the result it wants.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
int main() {

	// declare an int for number and input
	// use an if statement and else if or else

	int numPostive, numNegative, numZero;
	int input;

	cout << "Enter a number. " << endl;
	cin >> input;
	if(numPostive == input)
		cout << "It's postive." <<endl;
	else if (numNegative ==input)
		cout << "It's negative." << endl;
	else if(numZero == input)
		cout << "It's zero!" << endl;
	else
		cout << "Error!" << endl;
	return 0;
}
Last edited on
closed account (yR9wb7Xj)
Nvm, I figure it out I over thought the problem.
Here's my final result:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
using namespace std;
int main() {

	// declare an int for number and input
	// use an if statement and else if or else

	int num, postive, negative, zero;


	cout << "Enter a number. " << endl;
	cin >> num;
	if (num > 0)
	{
		cout << "It's postive." << endl;
	}

	else if (num < 0)
	{
		cout << "It's negative." << endl;
	} else if (num == 0) {
		cout << "It's zero!" << endl;
	} else {

		cout << "Error!" << endl;
	}

	return 0;
}
Topic archived. No new replies allowed.