C++ Homework help
3 posts
• Page 1 of 1
C++ Homework help
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
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
- lowellabraham
- Posts: 585
- Joined: Mon Sep 13, 2004 2:54 am
- Location: Long Island, New York
hey John!
thanks a lot bud! it works!
thanks so much! again!
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
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
- lowellabraham
- Posts: 585
- Joined: Mon Sep 13, 2004 2:54 am
- Location: Long Island, New York
3 posts
• Page 1 of 1
Return to HTML, CSS, and Scripts
Who is online
Users browsing this forum: No registered users and 4 guests