HELP


// lab02b.c : Defines the entry point for the console application.

#include <stdio.h>


int FunctionUser(void)
{

printf("Updating FunctionUser\n\n");
int n = 2;

return 10; //How DO I MAKE A RETURN PROPERLY





} // END int FunctionUser(void)


void main(void)
{

printf("\nTech104 Lab02\n\n");

int loop_counter = 1;

while(1) // while(?INSIDE HERE IS TRUE or 1?)
{

printf("Loop #:%d\n", loop_counter);
int FunctionStatus = FunctionUser();
printf("FunctionStatus=%d\n", FunctionStatus);
printf("\n\n");


int user_input = getchar();
if(user_input == '3')
{
printf("User entered 3!!!!!\n");
break;
}


loop_counter++; // increase loop counter by one.
}


printf("\nPress ENTER to quit");
getchar();

} // END void main(void)





How do I make it so that when the user inputs the number 2 the output would result to 10. Every time I activate it the output is always appear when I am running this program.
Hello and welcome to the forums! Please use the <> code button to the right of the text edit box when posting code.

What do you mean by "the output would result to 10"? I do not see if(user_input == '2') anywhere, so why do you expect that "the output would result to 10"?

Please clarify your question, so that we can better help you.

Unrelated to your question: void main is a bad habit. See this page for why http://stackoverflow.com/questions/204476/what-should-main-return-in-c-and-c
oh ok thanks for the tip and what I was trying to say was that how can I make the program to get an output of 10 when type in 2. Every time I run the program the output is already there BEFORE I typed in 2...
Let's take a look at the order of the commands inside your while loop:
1
2
3
4
5
6
7
8
9
10
11
printf("Loop #:%d\n", loop_counter);
int FunctionStatus = FunctionUser();
printf("FunctionStatus=%d\n", FunctionStatus);
printf("\n\n");


int user_input = getchar();
if(user_input == '3')
{
printf("User entered 3!!!!!\n");
break;

Line 2 calls FunctionUser() and line 7 asks for a character from the keyboard. If you want the program to output 10 after the user enters a character, you may want to move the FunctionUser stuff in the while loop beneath the user input stuff.
Topic archived. No new replies allowed.