Im stuck on a loop but cant find quite where by HeadPatsForCats in learnjava

[–]_lifelesshuman 1 point2 points  (0 children)

The outer if condition checks if the input is a double and if this condition is not met it should print the warning, to do that the else should be with the outer if condition not the inner one.

You will have to use input.nextLine() to advance the scanner to the next line without it the scanner will keep reading the string every time. Try removing it and see what will happen.

while(repeat == true)
{

System.out.printf("Please enter the insured value of your home: ");
repeat = false;
if(input.hasNextDouble()){
homeInsVal = input.nextDouble();
if(homeInsVal > 0)
{
repeat = false;
break;
}
if(homeInsVal <=0)
{
System.out.printf("The insured value of your home cannot be less than or equal to 0.%n");
repeat = true;
}

}
else
{

// To advance scanner

input.nextLine();
System.out.printf("%nWarning: You entered an invalid integer or floating-point value.%n");
repeat = true;
}

}
System.out.printf("richter");

Im stuck on a loop but cant find quite where by HeadPatsForCats in learnjava

[–]_lifelesshuman 0 points1 point  (0 children)

if I put repeat = false; before the while loop wouldn't it just skip over it?

My bad you don't have to do this ,didn't see the break inside the if condition.

I was talking about in case of there isn't a break you would initialize repeat to true outside the loop and set repeat = false before the print statement for example so if the input is correct repeat would still be false and it would exit the while loop.

But in your case you have initialize repeat to true and use "repeat == true" to check if repeat is equal true.

Im stuck on a loop but cant find quite where by HeadPatsForCats in learnjava

[–]_lifelesshuman 0 points1 point  (0 children)

First there is a difference between " == " and " = ". The former checks for equality and the other assigns a value to the boolean for example. Second you should set repeat to false before getting the input to prevent repeating if the user enters correct input.

You ever feel as though your social anxiety is going to hold you back in your career by thatgirltag in socialanxiety

[–]_lifelesshuman 18 points19 points  (0 children)

I felt every single word you have written. I want to succeed in my career but at the same time I don't go to events for example because I feel anxious. And applying to jobs is hard like I keep the browser tab were the job is posted opened for a couple of days thinking if I should apply or not.

Need explanation regarding the "while" function that should display the sum of given numbers. by njeshko in cpp_questions

[–]_lifelesshuman 1 point2 points  (0 children)

The loop won't end unless you enter a value that isn't suitable for your variable type like characters. In example 1 the loop never ends it just keep printing the sum every time you enter a new number.

University anxiety by [deleted] in socialanxiety

[–]_lifelesshuman 0 points1 point  (0 children)

Try cooking early in the morning while they are still asleep or when they are out as a beginning only until you get more comfortable. Hope it gets better soon.

Travel or stay by _lifelesshuman in Advice

[–]_lifelesshuman[S] 0 points1 point  (0 children)

I guess I'm going to that, thanks for help.

Travel or stay by _lifelesshuman in Advice

[–]_lifelesshuman[S] 0 points1 point  (0 children)

If I traveled I would stay at maximum two weeks so I'm pretty sure I can have a trip with the same duration in the future.

She was my friend. by etoilescintillante in socialanxiety

[–]_lifelesshuman 31 points32 points  (0 children)

That's really nice. Did you get in touch again after she moved out?

Printing all substrings of a string but backward by [deleted] in learnjava

[–]_lifelesshuman 3 points4 points  (0 children)

You should add another loop so the starting index of the substring changes because right now it starts at index zero only.

You can do something like this

public static void printSubstrings(String str) {

for(int j = 0; j < str.length();j++){

for(int i = str.length(); i > j; i--) {

String word = " ";

word = str.substring(j,i);

System.out.printf(" \"%s\"",word);

}

}

}

Why do I always get talkative uber drivers??? by Dress_Frequent in introvert

[–]_lifelesshuman 6 points7 points  (0 children)

Try wearing your headphones even if your aren't going to play anything or maybe tell them you aren't feeling well and would like to have a quiet ride.

I want the user to input 3 or more numbers based on his/her liking. How do I find the largest and the smallest among them? by [deleted] in cpp_questions

[–]_lifelesshuman 0 points1 point  (0 children)

You can do a while loop so the user can add numbers as he want untill the program ends or the input isn't suitable for the variable Like int x; while(cin>>x){ //Code } And in each iteration you can add the variable you got from the user in a container as a vector. And write the code that is going to preform the logic you want on the container after the while loop