Requirements
Ask the user to enter six numbers. Three of the numbers will be odd and three of the numbers will be even. The numbers can be entered in any sequence. Write a program that identifies the smallest number within each odd/even category.
Example run
5
2
4
7
9
6
The smallest even number is 2
The smallest odd number is 5
Assumptions:
1) The user will enter three odd numbers and three even numbers. We just don’t know in what sequence it will be entered.
2) The user will not enter zero because it is neither odd nor even
3) The user can enter negative or positive numbers
Use only what we have covered in class (Nothing more !)
Use the mod operator (%) to determine whether a number is odd or even)
This probably so easy and you're not thinking into it.
Here's some hints:
*NUMBER % 2 will return 0 or 1. guess which numbers returns a 1.
*You don't need to store anything but the smallest odd or even. So no need to worry about more than 3 variables.
*Positive or negative is not a catch or a problem. Negatives are just smaller numbers. It just warns you to not use unsigned int.
* Remember if else statements and do some comparison with the less than operator (<)
@kash kow ken
hey nice - this works! you devide up the numbers into odd and even ones and then sort each group smallest first :) but you still have to return the smallest even and odd numbers to the user, something like
The smallest even number is 2
The smallest odd number is 5
cdoubleplus, yes, I didn't read the whole thing correctly... haha I thought I had to divide them into even and odds... then take those and sort them from small to big haha.
having a static variable is nice too... i didn't think of that... also how you used the streams on cin... I didn't think of that either... but I'm starting today on the iostream library.
Why are you people outright doing his homework for him? Do you WANT more mediocre programmers on the market?
Also, kash kow ken, why are you using global variables? Do you not know how to pass arrays as parameters?
Well, since you people have already posted solutions to his problem, I'll post mine. Why did none of you check your input to make sure the numbers were actually even and odd? What if the user types in 6 even numbers?
@packetpirate
:( don't be angry with us plz - its just fun to solve those problems :) and in the end iCPP sees how it works and is motivated for next lesson?!
@kash kow ken
yeah your devision of the numbers into two sets and sorting has done the work - now you just have to take the first number of each set? so it was correct... we both would get all points I guess
@iCPP
how many points do we get for that problem solving? :)
@cdoubleplus
But you're not doing him any favors by doing the work for him. If you don't want the market to be flooded with talentless programmers, then you need to stop doing their work for them. They're never going to learn anything by having others do their homework for them.
@iCPP
ok - u heared what uncle packetpirate said? never introduce your questions whith words like this: "This is a problem that I got from class..." if you want us to answer your quests :)
Don't post homework questions
Programmers are good at spotting homework questions; most of us have done them ourselves. Those questions are for you to work out, so that you will learn from the experience. It is OK to ask for hints, but not for entire solutions.
You are violating them right now. He's not supposed to post homework questions, and you are not supposed to give the solutions. In programming classes the students are supplied with the knowledge they need to solve their problems.
@cdoubleplus: Alright, next time I won't introduce like that :). This is my second hw in C++ program. I'm really new with C++. I've just learned some from high school. I just want to have a whole to program to see how I can figure out, and also prepare for the next lesson. Because after I turn it in, I won't see the solution from the teacher. And I don't know how many point for this.
@All: I really appreciate for your time. I'll review carefully all of your works