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.

it is not recognizing nested if statement

+2 votes
asked Jun 15 by Vishal P Damodar (190 points)
#include <stdio.h>

int main()
    char answer;
    int no;
    printf(" pick a y or n;");
    if(answer == 'y')              //first if statement.
        printf("how many ?");
        if(no == '1')                 // Second if statement.

    return 0;


pick a y or n;y

how may? 1

thats it it does not return success if choose 1.

2 Answers

0 votes
answered Jun 29 by AUM MUDALIAR (140 points)

error : you have used ''(inverted commas) in if condition for an integer 

reason :  inverted comas are used only when your scanned input is an character .

for expected output edit  : if(no ==1)

0 votes
answered Jun 29 by Peter Minarik (40,320 points)

To the question "how many" you're supposed to answer 49 as the ASCII code of the character '1' is 49.

In line

if(no == '1')                 // Second if statement.

you do not compare no against the number 1, but against the the character 1 (character literals are within single quotes or apostrophes)

So either this (enter the character code for '1', that is 49), or do as AUM MUDALIAR suggested and make sure you compare against the a number, not a character.

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.