i have this question to exercise for my midterm but i don't know how to solve it,,i mean i have the idea but i don't know how to write it in c++ program, please help me in this,, i started to solve but its wrong and incomplete, here is the question:
Write a C++ program to perform the following:
• Read a positive integer n from the keyboard. Assume n is always an even number.
• Read n positive integers from the keyboard.
• Find the maximum of the first half of integers and the minimum of the last half of integers.
• Find the sum of all even numbers and the average of all odd numbers.
___________________
#include<iostream>
using namespace std;
int main()
{
int N,i=1,odd=0,even=0,cond,num,max,min;
double avg;
cout<<"please enter number of integers : "<<endl;
cin>>N;
cond = N/2;
max = num;
min = num;
while(i<=N)
{
cin>>num;
{if (i<=cond && num > max)
max = num;
else
min = num;}
i++;
}
cout<<"max is: "<<max<<endl;
cout<<"min is: "<<min;
return 0;
}
I think the way to approach your question is to focus your attention on just one aspect at a time. For example, look at just "Find the maximum of the first half of integers" to begin with. Only when you are satisfied with that, start to look at the next part, "the minimum of the last half of integers".
Break it down into bite-sized pieces each of which is a manageable task. Hopefully, before you know it, the whole thing will have dropped into place.