Welcome to the iTechForums.
If this is your first visit, be sure to check out the
FAQ by clicking the link above.
You may have to
register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
To register now click here.
|
Latest Threads
Advertisements
Forum Statistics
Threads:
Posts: 2
Members:
Number of Users Online:
Welcome to our newest member, |
|
 |

05-12-2008, 09:24 AM
|
|
Junior Member
|
|
Join Date: May 2008
Posts: 2
|
|
C++ Algorithm Help?
I don't even know where to begin on this problem somebody please help me out. If you don't know please do not answer!
Write an algorithm to read a sequence of integers, ignoring all numbers that are less than 1. Count how many even and odd numbers there are, and print these counts. For example, with input 7 25 100 2 -6 1 0 3, the output should be
Even = 2, odd = 4
There were two even numbers (100 and 2), four odd numbers (7, 25, 1, and 3), and two numbers were ignored (-6 and 0). Your algorithm should work for any input, not just this example.
|

05-12-2008, 09:25 AM
|
|
Junior Member
|
|
Join Date: May 2008
Posts: 1
|
|
It's been a LONG time since I wrote any C++, so I can't / won't write your whole program for you.
You need an odd counter and an even counter variable. Decide how many numbers you will evaluate. That will be your FOR loop count. Initialize your counters.
to determine odd or even, use modulus. I forget what the mod operator is in c++. I also forget the syntax of the CIN and COUT etc... and you have to include iostream, or something like that...
int oddCount = 0;
int evenCount = 0;
int userInput = 0;
for(int i=0, 6, i++)
{
CIN>userInput;
if(userinput>0)
{
if(userInput%2 == 0)
evenCount++;
else
oddCount++
}
}
COUT yer variables.
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
All times are GMT. The time now is 08:34 PM.