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
-1
votes
3 answers

A program that counts that maximum streak of heads and tails

This is what I have so far, but I can't seem to figure out how to do it. I am so far only able to store the total amounts of heads and tails flipped. import java.util.*; class Main { public static void main(String[] args) { int heads =…
johndoe123
  • 1
  • 1
  • 1
-1
votes
1 answer

Nested If If statement is skipping user's chance to input data for the second question

Updated to describe the issue more accurately C++ Language I am trying to use a nested if if statement for learning purposes (tutorial following along with). I am aware the logical && operator would be ideal for this situation. Anyways... The nested…
-1
votes
2 answers

How to do nested if - else with 4 numbers to find biggest number

public class NastingIfElse { public static void main(String[] args) { int a = 998 , b = 857 , c = 241 , d = 153; int result; if ( a > b ) { if ( a > c ) { if ( a > d ) { …
Om Patel
  • 3
  • 1
  • 2
-1
votes
1 answer

How to simplify if else with four different conditions

How can I simplifyy this code of mine?
ghabriel
  • 123
  • 9
-1
votes
1 answer

For loop runs through an ArrayList of objects and checks their names to display them in GUI but Error Message still shows up

I've decided to programm a search system for finding students and teachers in a school via GUI. It is an OOP and need some tweaking here and there, but there is one issue which doesn't seem logical to me. When I'm searching for a teacher, I have to…
-1
votes
4 answers

Program to find biggest of four numbers using nested-if

Sir/Ma'am, I do not know what may be that I'm doing wrong. Logic- wise everything appears correct to me. The braces seem placed in the correct positions as well. Then why is it that I'm receiving the following error messages? 32 8 [Error]…
Bao
  • 25
  • 1
  • 1
  • 10
-1
votes
1 answer

what code i use to ask the Quantity and Payment?

I think the problem starts before the nested if switch because at the end of the code it should output the result of sales = quantity * price and change = payment - total amount and asking quantity and Payment #include main() { int…
laura
  • 19
  • 5
-1
votes
2 answers

MINIFS using OR function

I’m trying to find the minimum date in column B if any cell in columns E, F, or G contains the word banana. Give the minimum date in column B IF: column E contains “banana” OR IF: column F contains “banana” OR IF: column G contains “banana” I’m…
que syrah sarah
  • 231
  • 1
  • 4
  • 14
-1
votes
3 answers

How to break through if statement inside a nested loop in java

While solving a problem on java I am finding trouble breaking through the if statement which is inside a for loop and this for loop is inside another if statement. The code fragment is as below: package experment; public class myclass_2{ public…
Dev Joshi
  • 73
  • 1
  • 1
  • 8
-1
votes
2 answers

What is a shortcut for a nested if greater than function in excel?

=IF(Z2>=CU25,CV25,IF(Z2>=CU24,CV24,IF(Z2>=CU23,CV23,IF(Z2>=CU22,CV22,IF(Z2>=CU21,CV21,IF(Z2>=CU20,CV20,IF(Z2>=CU19,CV19,IF(Z2>=CU18,CV18,IF(Z2>=CU17,CV17,IF(Z2>=CU16,CV16,IF(Z2>=CU15,CV15,IF(Z2>=CU14,CV14,IF(Z2>=CU13,CV13,IF(Z2>=CU12,CV12,IF(Z2>=CU11…
spenc044
  • 29
  • 1
  • 7
-1
votes
2 answers

Incorrect output with Nested IFs in vba

I want "TRUE" output only if individual values are also equal besides the total values.I am just including a part of code for which I am not getting correct output. I am trying to get the output as attached but I am receiving incorrect output with…
HobbyCoder
  • 45
  • 9
-1
votes
2 answers

Am I using modulus wrong? My program will always enter the if statement

bool leap = false; int leapd = 28; if (year % 100 == 0) { if (year % 400 == 0) { leap = true; } else { leap = false; } } else if (year % 4 == 0) { leap = true; } else { leap = false; } if (leap = true) { …
-1
votes
1 answer

Python multiple if-else in the same line

I know this is possible: a, b = 5, 10 print 'a' if a > b else 'b' # outputs b However, what if I had another variable 'c'? How do I make them print in the same line using the same type of logic as those two variables? Something like? a, b, c =…
QuestionEverything
  • 4,809
  • 7
  • 42
  • 61
-1
votes
4 answers

Combine if statements with logically related conditions

I have this situation. **Updated my code and it works in all the way i want it to. *clarified the code as requested(full program) if i give Start time: 2:30:30 Stop time: 2:30:25 i should get elapsed: 23:59:55 get it? it crossed midnight...into…
loki47_ch
  • 41
  • 6
-1
votes
5 answers

nested for loop only iterates one time

I am trying to create a counter that finds what it needs to count from one file and what it should count from another file. It opens file1 and finds a city and its population separated by a dash, and file2 shows a city name and the crime separated…
sidfvdx125
  • 15
  • 5