C++ programming also before this question i want it in c++ Q3. [ O points I writ
ID: 3595004 • Letter: C
Question
C++ programming also before this question i want it in c++ Q3. [ O points I write C++ programs to perform the falowinguks (A)15 points] - Require no more than 15 lines of code. · Ask user to enter the name (string) and a lock, namber Oategen for 2 persons from keyboard. Based on the comparison of 2 numbers, output messages o Inumbers are the same, output both names with same lucky number o Otherwise, output name of the person with the smaller lucky number. Finally, calculate if the smaller number is even or odd ( HINT: use % output proper message Sample Input/Output 2 Enter namel and testl: Tom 69 Enter namel and testl: Ali 77 Enter name2 and test2: Ahmed 77Enter name2 and test2 Jery 38 Ali and Ahmed both has lucky # 77 Tom has the smaller locky # 38 This is an odd lucky number This is an even lucky number clude cjostream> g namespace std in O
Explanation / Answer
string name1,name2;
int test1,test2,small;
cout<<endl<<"Enter Name1 and Test1: ";
cin>>name1>>test1;
cout<<endl<<"Enter Name2 and Test2: ";
cin>>name2>>test2;
if(test1 == test2){
cout<<endl<<name1<<" and "<<name2<<" both has lucky #"<<test1;
if(test1%2==0) cout<<endl<<"This is an even lucky number";
else cout<<endl<<"This is an odd lucky number";
}else{
small=test1 < test2?test1:test2;
if(small==test1) cout<<endl<<name1<<" has lucky # "<<small;
else cout<<endl<<name2<<" has lucky # "<<small;
if(small%2==0) cout<<endl<<"This is an even lucky number";
else cout<<endl<<"This is an odd lucky number";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.