Attention: PROnetworks has upgraded our forum from phpbb2 to phpbb3!!

Please head over to our new converted forum at: http://www.pronetworks.org/forums/

This old forum will remain 'read-only' until approximately February 2009. We look forward to seeing you at the new forum!
Author Message
lowellabraham
PostPosted: Thu Mar 06, 2008 3:07 am Reply with quote

PRO Level 13
 
 


Joined: 12 Sep 2004
Posts: 651
Location: Long Island, New York
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:

#include <iostream>
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;
   

   return 0;
   
}


I use Microsoft Visual C++ 6.0 as the compiler.
 
Back to top
NoReflex
PostPosted: Thu Mar 06, 2008 9:19 am Reply with quote

PRO Level 12
 
 


Joined: 17 Nov 2004
Posts: 609
Location: Romania
Hello!

To display the number of positive integers and whether there are more negative or positive integers you could use something like :



Hope this helps you.

Best wishes,
John!

PS : I tried to post the code here with or without the "code" tags but every time it would post only parts of it.
 
Back to top
lowellabraham
PostPosted: Thu Mar 06, 2008 11:01 am Reply with quote

PRO Level 13
 
 


Joined: 12 Sep 2004
Posts: 651
Location: Long Island, New York
hey John!

thanks a lot bud! it works! smile

thanks so much! again!
 
Back to top
Back to top
Index >> Webmaster Domain & Code Room >> C++ Homework help

Page 1 of 1

 


Tired of the Ads? Registered users have 80% less adverts.