Thread: find & print the average of the odd numbers

  1. #1
    Registered User
    Join Date
    Oct 2010

    find & print the average of the odd numbers

    Write a C++ program that accepts three numbers from the user (All are integers):

    Such as:
    Enter the first mark: 3
    Enter the second mark: 25

    Enter the third mark: 23

    The program should find and print the average of the odd numbers greater than 5 and less than 100.

    this is my code :

    PHP Code:
    #include <vcl.h>
    #include "MT262io.h"// this is the library for the input and output//
    #pragma hdrstop


    #pragma argsused
    int main(int argccharargv[])
    int firstNum;
    int secondNum;
    int thirdNum;
    int average;
    firstNum=ReadIntPr(" enter the first number");
    secondNum=ReadIntPr(" enter the second number");
    thirdNum=ReadIntPr(" enter the third number");

    average >5) && (average <100)) {

    firstNum != 0)&&(secondNum != 0)&& (thirdNum != 0) {

    WriteIntPr("the average of the odd numbers is"+average);

    where are my mistakes and how can i fix them ?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > this is my code :
    Is it?
    There are a number of dumb mistakes - the kind tutors sometimes put into boilerplate code to hand out to students in a "fix the errors in this code" homework.

    > where are my mistakes and how can i fix them ?
    You compile it, and fix the syntax errors.
    You run it, and fix the logic errors.

    First one is free
    > average=(firstNum+secondNum+thirdNum/3);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help to print even numbers
    By ortegac in forum C Programming
    Replies: 3
    Last Post: 05-21-2006, 12:01 AM
  2. Prime odd numbers
    By Lurker in forum C Programming
    Replies: 27
    Last Post: 03-24-2003, 04:09 PM
  3. Replies: 4
    Last Post: 03-03-2003, 03:52 PM
  4. Homework help
    By Jigsaw in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 05:56 PM
  5. adding odd numbers
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 09-06-2001, 01:44 PM