Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how do i use scanf in an if else function to output a print statement from the input

+3 votes
asked Jan 8, 2022 by george pearse (150 points)

2 Answers

+3 votes
answered Jan 9, 2022 by Peter Minarik (86,040 points)

scanf() does not output anything, it reads from the standard input.

Maybe can you share some code or explain in more detail what you're after?

Here's a silly example using scanf() and printf():

#include <stdio.h>

int main()
{
    int age;
    printf("How old are you? ");
    scanf("%d", &age);
    if (age >= 18)
        printf("You are legally and adult.\n");
    else
        printf("You are legally not an adult yet.\n");

    return 0;
}
0 votes
answered Jan 21, 2022 by abidhossan2231 (140 points)
#include <stdio.h>
int main()
{
    int id;
    printf("Input your Student id = ");
    scanf("%d", &id);
    if (id <= 35)
        printf("You are legally For section A.\n");
    else
        printf("You are legally For other section.\n");
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...