hey guys, I am a beginner to C++. I take Introduction to C++ in school. My prof assigned us this homework. Here is the assignment:
1) Write an interactive C++ program to prompt a user for 5 integer values, one at a time.
2) As the values are read, count the number that are positive (greater than 0) and the number that are negative (less than 0).
3) When the 5 values have been processed, display the number of positive values and the number of negative values.
4) Also, display the message "more positive" or "more negative" as appropriate based on the result.
So far I only found a way to display the number of either the positive integers or the negative. here is my code:
- Code: Select all
using namespace std;
int main ()
int number, count;
count = 0;
for (int i=1; i<=5; i=i+1)
cout << "enter number: ";
cin >> number;
if (number < 0) count = count + 1;
cout <<"# of negative integers = " << count << endl;
I use Microsoft Visual C++ 6.0 as the compiler.