Answer to Question #224891 in C++ for utsha

Question #224891

Now, imagine your younger brother is working in a project with you. Both of you need to

solve negative number issue input by user. But you want to restrict information type

which can be send as error notification by your brother. So, write a program to handle the

scenario.


1
Expert's answer
2021-08-10T17:41:17-0400

This problem has several solutions first one is at the beginning of the program deeloper can ask the user not input the negative number:


int n;
cout << "Input any non-negative number: ";
cin >> n;


The second solution is developer can keep asking the user for a input until he/she inputs a valid(non-negative) number.

int n = -1;
cout << "Input any non-negative number: ";
while (n < 0) {
    cin >> n;  
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS