Answer to Question #156271 in C++ for allan

Question #156271

Allow the user to input two integers. Variables: Num1 and Num2 (Num1 must be less than Num2, values must be a positive number) (use loop); create a user-defined function to validate the user's input.


1
Expert's answer
2021-01-17T08:09:23-0500
#include<iostream>
using namespace std;

void validation(){

    int num1,num2;
    bool valid=false;
    while(valid==false){
    cout<<"Enter First number"<<endl;
    cin>>num1;
    cout<<"Enter second number"<<endl;
    cin>>num2;
    if((num1<num2) && (num1>=0)){
    
    valid=true;
    
    cout<<"first value="<<num1<<" second value="<<num2<<endl;    
    
    }else{
    
    
    cout<<"Entered wrong values:\n both values must be positive and first value must be less than second value\n try again"<<endl;
    
    }

    
    }


}


int main(){

validation();

return 0;}


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