Ask your own question, for FREE!
Computer Science 16 Online
OpenStudy (anonymous):

help please ='[ new to C this is my code so far: #include #include int main() { int user_num; printf("enter num: "); scanf("%d%d%d%d%d", &user_num,&user_num,&user_num,&user_num,&user_num); while (user_num >=1 && user_num <= 100) { printf("%d\n", user_num); user_num++; } return 0; } what i need to do is have the user input 5 numbers from 1- 100. for ex. 10,15,50,45,2 now smallest number to the biggest number must be the output 2 3 4 5 6... 10... 15 16... 50 #s outside the range of 1-100 won

OpenStudy (anonymous):

wont show* hopefully i made sense >.<

OpenStudy (anonymous):

You are assigning all of the input values for the same variable, i.e., every digit scanf reads in is allocated at user_num's memory, replacing the old one. You should create 5 different variables, like num_1, num_2, ..., num_5 (you can use an array also, it is generally better to use an array, but if you don't know about it just yet, create 5 different variables). Then, your program should determine, from the input, which one is the smallest and which one is the largest (and assign those values to two different variables, say, small and large). Only then, your loop will output every number from the smallest input to the largest, if you code it like while (small <= largest) { printf("%d\n", small); small++; }, or something like that. To check whether or not the input is outside the range 1-100, just do if (large > 100) /* code */ and if (small < 1) /* code */

OpenStudy (anonymous):

ty =]

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!