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

Write in C++ Code Goals: Practicing loop/repetition structures and functions Pro

ID: 3862750 • Letter: W

Question

Write in C++ Code

Goals: Practicing loop/repetition structures and functions

Problem: Describe a function that will prompt the user to enter 50 whole numbers and count how many even and odd numbers were entered (0 should be considered an even number). The function should send back to the function call how many odd and even numbers were entered.

Your main function should be a driver program that will call the function, then output the values sent back to the function call.  

Your function should prompt the user to enter the 50 numbers one at a time, determine how many are even and how many are odd (zero should be determined as even), and send back to the function call how many were even numbers and how many are odd numbers were entered.

Your function definition should occur after main.

Do not use any concepts beyond Chapter 6 (e.g. arrays). Remember, your code should contain comments for each function other than main that states the purpose of the function, input to the function (both input from the function call and interactive input), output from the function (both information sent back to the function call and interactive output), and processing performed in the function.

Explanation / Answer

//

// main.cpp

// chegg

//

// Created by Nishant Kumar on 16/03/17.

// Copyright © 2017 Nishant Kumar. All rights reserved.

//

#include <iostream>

using namespace std;

int evenorodd();

int main(int argc, const char * argv[]) { //main program which calls the function

// insert code here...

evenorodd(); //function call

return 0;

  

}

int evenorodd(){ //function implementation

int i=1;

int n;

int odd=0,even=0; //count even and odd

while(i<=50)

{

cout<<"Please enter the number:"<<i<<endl;

cin>>n;

if(n%2==0||n==0)

even=even+1;

else

odd=odd+1;

i=i+1;

  

}

cout<<"total count of even is:"<<even<<endl;

cout<<"total count of odd is"<<odd<<endl;

return 0;

}

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