Question
IN C ++ PLEASE!!! Write a program that asks the user for integers; stop when the user enters a zero (0). For each nonzero number,
IN C ++ PLEASE!!! Write a program that asks the user for integers; stop when the user enters a zero (0). For each nonzero number, count how many even, odd, positive and negative values are entered. Display the results as shown below:
1
2
3
4
5
6
7
8
-9
-10
-11
-12
0
You entered:
6 even numbers
6 odd numbers
8 positive numbers
4 negative numbers
So far, this is my code:
#include
int userEven = 0; int userOdd = 0; int userPos = 0; int userNeg = 0; int num;
cin >> num; cout << num << endl;
while (num != 0) { if ((num % 2) == 0) { userEven++; } else { userOdd++; } break; if (num < 0) { userNeg++; } else { userPos++; } }
cout << "You entered: " << endl; cout << userEven << " even numbers" << endl; cout << userOdd << " odd numbers" << endl; cout << userPos << " positive numbers" << endl; cout << userNeg << " negative numbers" << endl; return 0; }
This is not coming out how my example was above. Please let me know if you can help! :)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started