I need to write a program that reads 10 integers and determines and prints out the minimum integer.
The hint is not to compare 10 integers at one time.
The question is how do I compare one at a time using if-else statements?
I need to write a program that reads 10 integers and determines and prints out the minimum integer.
The hint is not to compare 10 integers at one time.
The question is how do I compare one at a time using if-else statements?
Get one thing down at a time. First read in 10 integers, that right there will involve a loop. Then you can worry about comparing, which will also involve looping with if-else statements.
I can't use loop since we haven't covered it in class.
Well then I would suggest reading in one number. Set that initial first number equal to smallest integer. After that its just a matter of reading in 9 other numbers manually and comparing each one to the smallest_variable.
Read the first number and save it in a variable named min for example.Then read the second variable.If it's value is lees than min ,then set min to the number you just read and so on
How do you save it?
So do I ask the user for the integers one at a time or all at the same time?
One at a time. Scanf after Scanf that is assuming you are not allowed to use loops.
Do you have to declare all variables in the beginning or can you declare it anywhere (just before you use it)?
It depends on the standard you are using.With the old one you have to declare them at top.With the new one - C99 - you can declare them anywhere just before using them
For C89, you must declare all of your variables at the beginning of a scope block. It depends if you are compiling under that standard, however I would still suggest declaring all variables at beginning to adhere to original C standard.
I know I should scanf one at a time, but what about printf for prompting the user to enter 10 integers, should i do that 1 at a time as well?
You could print the message to them, to enter 10 numbers. Best to count the number they have entered, as they are being entered though, because user's are notorious for giving bad input from the keyboard.
I you sure you can't use a loop or call a function to help with this? This is worse than watching little short legged dachshunds dogs, in a race.
Last edited by Adak; 10-07-2012 at 11:47 AM.
Yea, I can't use loop, only can use if, else, switch.
Try this:
prompt user for input
store input in variable
print out the variable on the screen.
The best programs are written a little bit at a time - The pseudo written above is a great place to start.
Fact - Beethoven wrote his first symphony in C