Write a program that asks the user to input three different integers. Write a fu
ID: 3604227 • Letter: W
Question
Write a program that asks the user to input three different integers. Write a function called numberStyle for this program that will accept each integer (one at a time) and return the following:
· If the integer is even, return 1
· If the integer is odd, return -1
· If the integer is zero, return 0
In main, after calling the function output the appropriate message describing the integers.
Sample run:
Enter 3 integers separated by a space and press <Enter> 10 5 0
Integer 10 is even
Integer 5 is odd
Integer 0 is zero
Explanation / Answer
#include<iostream>
using namespace std;
int main(){
int a,b,c;
cout << "Enter 3 different integers separated by a space and press <Enter> :";
cin >> a >> b >> c;
if (a == 0){
cout << "Integer " << a << " is zero ";
}
else if (a % 2 == 0){
cout << "Integer " << a << " is even ";
}
else if (a % 2 != 0){
cout << "Integer " << a << " is odd ";
}
if (b == 0){
cout << "Integer " << b << " is zero ";
}
else if (b % 2 == 0){
cout << "Integer " << b << " is even ";
}
else if (b % 2 != 0){
cout << "Integer " << b << " is odd ";
}
if (c == 0){
cout << "Integer " << c << " is zero ";
}
else if (c % 2 == 0){
cout << "Integer " << c << " is even ";
}
else if (b % 2 != 0){
cout << "Integer " << c << " is odd ";
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.