Why is it not throwing exceptions when I enter Zeros? Help me correct the mistake | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is it not throwing exceptions when I enter Zeros? Help me correct the mistake

Write a program that prompts the user to enter a length in feet and inches and outputs the equivalent length in centimetres. If the user enters a negative number or a nondigital number, throw and handle an appropriate exception and prompt the user to enter another set of numbers. https://code.sololearn.com/cgTP3EAT7p9o/?ref=app

21st Nov 2019, 8:57 PM
MASANGA KAUKA MUDENDA
MASANGA KAUKA MUDENDA - avatar
7 Answers
+ 4
You have written && inches, that is the problem. Because this means: If feet<=0 AND inches !=0. So if you enter 0 for feet and something for inches, you do get your error. But if both are zero, you don't get the error. For clarity, once again: if(inches) means the same as: if(inches != 0)
21st Nov 2019, 9:30 PM
HonFu
HonFu - avatar
+ 1
Cheers thanks
22nd Nov 2019, 10:34 AM
MASANGA KAUKA MUDENDA
MASANGA KAUKA MUDENDA - avatar
+ 1
Ruchika Tripathi honest how is this song related to my question ❓
24th Nov 2019, 11:05 AM
MASANGA KAUKA MUDENDA
MASANGA KAUKA MUDENDA - avatar
0
Are negative numbers digital numbers?
22nd Nov 2019, 6:04 AM
MASANGA KAUKA MUDENDA
MASANGA KAUKA MUDENDA - avatar
0
I'm still failing to correct it. Please help me.
22nd Nov 2019, 9:07 AM
MASANGA KAUKA MUDENDA
MASANGA KAUKA MUDENDA - avatar
0
~ swim ~ can you kindly give me an outline of the code you're talking about. I'm completely lost. Please
22nd Nov 2019, 9:40 AM
MASANGA KAUKA MUDENDA
MASANGA KAUKA MUDENDA - avatar
0
~ swim ~ it is not throwing an exception of one 0 is put plus a positive number but if both zeros are put. It is not throwing the exception
22nd Nov 2019, 11:11 AM
MASANGA KAUKA MUDENDA
MASANGA KAUKA MUDENDA - avatar