Questions tagged [nested-if]

This tag refers to a code structure in which multiple if-statements are placed in a "nested" form (i.e. one if-statement is contained within another).

Use this tag for questions related to constructing, maintaining, or refactoring nested if-statements.

428 questions
-3
votes
2 answers

C++ condition is right but does not work

I'm trying to build a simple program that asks for a grade whether it is numerical or general weighted average e.g. 75, 1.5 respectively. And when the user input a non numerical number a stated in the if condition, it prints error as stated also in…
-3
votes
4 answers

my else is not recognizing the proper if

the else i have labeled has an error saying it is unnecessary. How can I get that else to line up with the first if? if (heading < 270 && heading > 90) directionToFace= 'S'; if (heading > 180) { degreeToWalk…
Aiden
  • 1
  • 1
-4
votes
3 answers

Write a program to find the greatest of four numbers

I am new to Programming and currently learning C, so I don't know much about this concept but I was learning Conditional Instructions and at that time, my instructor [I am learning online from YouTube] explained me about logical operators. He…
-4
votes
2 answers

"if" statement does not follow my instructions C#

So basically I am trying to make it interpret if I input more than 200 horsepower, the speed should change increasingly by 15, which works, if I input "BMW" then the speed should go up with 10, which doesn't work and I cant figure out why, and if…
-4
votes
4 answers

Can someone explain thos code to me? (i % 2 == 0 ?)

I'm trying to work through a project which creates a chessboard layout. The only part I can't get my head around is this line if (row == 0) singleSquare.setBackground( i % 2 == 0 ? Color.black : Color.white ); else if (row != 0) …
user3216557
  • 81
  • 2
  • 4
  • 9
-5
votes
3 answers

A leap year determining C program is not giving any output when inputting 2000, 1900 or 2100 as an input

When I am running this C program, and giving 2020, 2024 or other years perfectly divisible by 4, then I am getting expected output i.e. it is a leap year. But when I am giving a century year : 1900, 2000 or 2100 etc. as an input, then it's not not…
-6
votes
2 answers

What is the difference between these two code structure? Nested vs single line code

if (x>0 && x<6) { break; } else if(x>6) { break; } versus if (x>0) { if (x<6) { break; } } else { if (x>6) { break; …
-8
votes
1 answer

C++ Do while loop condition not working

#include #include #include using namespace std; int main(){ int gnumber, rnumber; char choice; int tries; do { cout << "Welcome to the Number Guessing Game!" << endl; cout << endl; // breakline …
1 2 3
28
29