A Digital Age Deserves A Digital Leader

C++ Homework help

C++ Homework help

Postby lowellabraham » Thu Mar 06, 2008 7:07 am

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
#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.
Workstation:
CPU: Intel Core 2 Quad Q8200 2.33GHz 1333 MHz FSB
PCB: GA-EP45-UD3R
RAM: 4X1GB DDRII 800MHz
GPU: Nvidia 8400 GS
HDD0: WD 150 GB 10,000 RPM
DISPLAY: 24' Dell UltraSharp Widescreen
Server: Intel Pentium 4 3.40GHz HT 800MHz FSB / 4X1GB DDRII 800MHz / 1X200GB 7200rpm / Windows 2003 Server Standard R2
PRO Level 12
Posts: 585
Joined: Mon Sep 13, 2004 2:54 am
Location: Long Island, New York

Postby NoReflex » Thu Mar 06, 2008 1:19 pm

Hello!

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

Image

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.
PRO Level 10
User avatar
Posts: 431
Joined: Wed Nov 17, 2004 8:41 pm
Location: Romania

Postby lowellabraham » Thu Mar 06, 2008 3:01 pm

hey John!

thanks a lot bud! it works! :)

thanks so much! again!
Workstation:
CPU: Intel Core 2 Quad Q8200 2.33GHz 1333 MHz FSB
PCB: GA-EP45-UD3R
RAM: 4X1GB DDRII 800MHz
GPU: Nvidia 8400 GS
HDD0: WD 150 GB 10,000 RPM
DISPLAY: 24' Dell UltraSharp Widescreen
Server: Intel Pentium 4 3.40GHz HT 800MHz FSB / 4X1GB DDRII 800MHz / 1X200GB 7200rpm / Windows 2003 Server Standard R2
PRO Level 12
Posts: 585
Joined: Mon Sep 13, 2004 2:54 am
Location: Long Island, New York

Return to HTML, CSS, and Scripts

Who is online

Users browsing this forum: No registered users and 0 guests