AVGTIL0 – Write a program to accept integers from the keyboard until a zero is entered. Print the sum and average of the even numbers. Ignore any odd numbers in your calculations and print an appropriate message. I am working on this program more than two days.
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <stdio.h>
using namespace std;
void Pause()
{
string junk;
cout << "Press any to continue ... ";
cin.ignore();
getline(cin, junk);
}
int main()
{
// declare file variables
// int x, evenNumber, averageEven;
int entNum, ans;
int even, x;
int odd;
// get input
cout << "What is the integer of X: ";
cin >> x;
cout << endl;
//display results
do
{
even=0;
odd=0;
scanf("%d",& entNum);
ans = entNum%2;
if(ans==0)
{
even++;
}
else if(ans!=0)
{
odd++;
}
}
while(entNum!=0);
// if (x %2==0)
// else if ( x==0)
// averageEven = evenNumber
cout <<" average of the even numbers is: "<< even << endl;
// freeze screen
Pause();
return (0);
}
Tareq_1 0 Newbie Poster
Tareq_1 0 Newbie Poster
Andrew_36 4 Newbie Poster
brothman01 0 Newbie Poster
brothman01 0 Newbie Poster
brothman01 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.