Tuesday, July 28, 2009

C++ Program?

This assignment will require...





*


Variables and variable declaration


*


Basic input and output


*


The assignment operator and arithmetic operations


*


The if statement and boolean expressions


*


The while or for command...





Design and code a progarm that will...





*


accept up to twentyfive integer values...


*


return the average of all the even numbers..


*


return the average of all the odd numbers.





Make sure your output is labeled and easy

C++ Program?
#include%26lt;iostream%26gt;





int main(){


int temp=0;


int total_even=0;


int total_odd=0;


for(i=0;i%26lt;25;i++){


cout%26lt;%26lt;endl%26lt;%26lt;"Please enter an integer:\n";


cin%26gt;%26gt;temp;


if(temp%2==0){


total_even+=temp;


}else{


total_odd+=temp;


}


}


cout%26lt;%26lt;endl;


cout%26lt;%26lt;"The average of the even integers is:"%26lt;%26lt;total_even/25.0%26lt;%26lt;endl;


cout%26lt;%26lt;"The average of the odd integers is:"%26lt;%26lt;total_odd/25.0%26lt;%26lt;endl;





return 0;


}











There you go. It inputs 25 integers, and outputs the average of the odds and of the evens separately.


No comments:

Post a Comment