I am currently learning c, and this is the code I am running. I am asking the user for input, and the only valid inputs are 0,1,2. 0 allows the user to quit the program. When I run this program and call the functions function1 and function2, the output I get after looping is:
#include<stdio.h>
int function2(int num3, char ch);
int function1(int num1, int num2, char ch);
int main()
{
int number, num1, num2, num3;
char ch;
do {
printf("Enter 0 (quit), 1, 2:");
scanf("%d", &number);
if (number == 1)
{
printf("Enter character, first number, and second number: ");
scanf("%c %d %d", &ch, &num1, &num2);
function1(num1, num2, ch);
}
else if (number == 2)
{
printf("Enter character and another number: ");
scanf("%c %d", &ch, &num3);
}
else
{
if (number == 0)
{
printf("Exit \n");
}
else
{
printf("Please reenter data. \n ");
}
}
}
while (number != 0);
return 0;
}
int function1(int num1, int num2, char ch)
{
printf("%d %c %d", num1, ch, num2);
}
int function2(int num1, char ch)
{
printf("%d %c", num1, ch);
Is the problem how I am using printf and scanf? I tried using fflush(stdout) but it didn't change the outcome.