Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a C+ program that takes n numbers from user (where, n is specified by u

ID: 3889705 • Letter: 1

Question

1. Write a C+ program that takes n numbers from user (where, n is specified by user). The number should in range of (1 to 100); if the number is not in the specified range, the program should alert the user that the number entered is out of range, and prompts the user to enter another number The program should then prompt the user to enter a series of integers and use a function isEven, which uses the modulus operator to determine whether the integer is even or odd. The function should take an integer argument and return true if the integer is even and false otherwise.

Explanation / Answer

#include<iostream>
using namespace std;

bool isEven(int v){
// if number modulus 2 is zero return true else return false
if(v%2==0){
return true;
}
else{
return false;
}
}

int main(){
int n,i,v;
cout << "Enter Range:";
cin >> n;
//validate input range
while(n<1 || n>100){
cout << "Number should between (1-100)" << endl;
cout << "Enter Range:";
cin >> n;
}
//Get user input and check if even or odd
for(i=0;i<n;i++){
cout << "Enter number:";
cin >> v;
if(isEven(v)){
cout << v << " is Even" << endl;
}
else{
cout << v << " is Odd" << endl;
}
  
}
return 0;
}
/*
sample output
Enter Range: 101
Number should between (1-100)
Enter Range: 0
Number should between (1-100)
Enter Range: -1
Number should between (1-100)
Enter Range: 2
Enter number: 4
4 is Even
Enter number: 5
5 is Odd
*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote