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.
#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;}
Comments
Leave a comment