Question

Write a program that accepts three even integers and determine the largest of the three numbers. The program should also compute the average of the numbers entered. The program should only compute the average and find the largest if all numbers entered are even. Note that the program should terminate and generate an error message if any of the numbers entered is not even. the output of the program should:

• Identify if all numbers are even
• Display which is the largest of all numbers entered
• Print the average

Could you post your attempt so far? It is much easier to help that way, and you will understand it better than if you just read someone else's code.

You said: "Help Me With this please...I'm just learning C++", but you didn't say what you want help with. Where are you stuck?

Check for even numbers: variable % 2 == 0

Chick for highest number: just use a variable to store the highest value and use an if statement to compare the present value to the highest value.

Average: I'm sure you can work out how to calculate an average so I won't bother with this one.

If you need more specific help then you'll have to be more specific in your question....

#include<iostream.h>
#include<conio.h>
int main()
{
 clrscr();
 int num,sum=0,big;
 for(int i=0;i<3;i++)
 {
  cout<<"\nType"<<i+1<<"num:";
  cin>>num;
  if(num%2!=0)
  {
   cout<<"The entered number is odd program is terminating";
   getch();
   return 0;
  }
  if(i==1)
  big=num;
  if(num>big)
  big=num;
  sum=sum+num;
 }
 cout<<"\nThe largest of all entered number is"<<big;
 cout<<"\nThe average of the number is:"<<sum/3;
 getch();
 return 0;
}

SNIP

Edited 7 Years Ago by happygeek: link removed

Comments
Lots wrong here.

ok....please don;t make fun of what i know and understand.

#include <stdio.h>
#include <conio.h>

void main()

{
int num1,num2,num3;
float average;

printf("Enter Three Numbers")
scanf(
float average;

do you want to write the programme in c or c++ because printf and scanf are used in c and not in c++

ok....please don;t make fun of what i know and understand.

#include <stdio.h>
#include <conio.h>

void main()

{
int num1,num2,num3;
float average;

printf("Enter Three Numbers")
scanf(
float average;

#include<stdio.h>
int main()
{
 int num,sum=0,big,i;
 float avg;
 clrscr();
 for(i=0;i<3;i++)
 {
  printf("\nType % dnum:",i+1);
  scanf("%d",&num);
  if(num%2!=0)
  {
   printf("\nThe entered number is odd program is terminating");
   getch();
   return 0;
  }
  if(i==1)
  big=num;
  if(num>big)
  big=num;
  sum=sum+num;
 }
 avg=sum/3;
 printf("\nThe largest of all entered number is:%d",big);
 printf("\nThe average of the number is:%f",avg);
 getch();
 return 0;
}

SNIP

Edited 7 Years Ago by happygeek: link snipped

#include<stdio.h>
int main()
{
 int num,sum=0,big,i;
 float avg;
 clrscr();
 for(i=0;i<3;i++)
 {
  printf("\nType % dnum:",i+1);
  scanf("%d",&num);
  if(num%2!=0)
  {
   printf("\nThe entered number is odd program is terminating");
   getch();
   return 0;
  }
  if(i==1)
  big=num;
  if(num>big)
  big=num;
  sum=sum+num;
 }
 avg=sum/3;
 printf("\nThe largest of all entered number is:%d",big);
 printf("\nThe average of the number is:%f",avg);
 getch();
 return 0;
}

SNIP

isn't this a bit too advanced for my beginners level? i get the concept tho

Edited 7 Years Ago by happygeek: link snipped from quoted text

isn't this a bit too advanced for my beginners level? i get the concept tho

As far as i've seen where you have stuck with your code, the program you want to creat itself is way too advanced for you aswell.

Don't try to go that fast. First walk, we'll run later, start with something easier than that and read more.

#include<stdio.h>
int main()
{
 int num1,num2,num3,sum,big;
 float avg;
 clrscr();
 printf("\nType num1:");
 scanf("%d",&num1);
 if(num1%2!=0)
 {
   printf("\nThe entered number is odd program is terminating");
   getch();
   return 0;
 }
 printf("\nType num2:");
 scanf("%d",&num2);
 if(num2%2!=0)
 {
   printf("\nThe entered number is odd program is terminating");
   getch();
   return 0;
 }
 printf("\nType num3:");
 scanf("%d",&num3);
 if(num3%2!=0)
 {
   printf("\nThe entered number is odd program is terminating");
   getch();
   return 0;
 }
 big=num1;
 if(num2>big)
 big=num2;
 else if(num3>big)
 big=num3;
 sum=num1+num2+num3;
 avg=sum/3;
 printf("\nThe largest of all entered number is:%d",big);
 printf("\nThe average of the number is:%f",avg);
 getch();
 return 0;
}

This code is much simpler to understand but wastes a lot of memory.

SNIP

Edited 7 Years Ago by happygeek: keep it onsite, link snipped

it was an actual assignment and the lecturer doesn't really care.

Your teacher doesn't care, but maybe you should. You got someone else to do for homework for you. Congratulations, you missed out on the chance to learn something from your own effort. Now what happens come exam time? Will you bring a laptop in to the exam and ask someone else to write it for you? Forums like this should be a place where you get help solving problems that you can't solve on your own and not a means of getting out of doing your own work. Just my 2 cents so you don't have to agree with me.

This article has been dead for over six months. Start a new discussion instead.