find & print the average of the odd numbers

This is a discussion on find & print the average of the odd numbers within the C++ Programming forums, part of the General Programming Boards category; Write a C++ program that accepts three numbers from the user (All are integers): Such as: Enter the first mark: ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    1

    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=(firstNum+secondNum+thirdNum/3);

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

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

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



            return 
    0;
    }
    //--------------------------------------------------------------------------- 
    where are my mistakes and how can i fix them ?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    > 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);
    Try
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 03:09 PM
  3. Replies: 4
    Last Post: 03-03-2003, 02:52 PM
  4. Homework help
    By Jigsaw in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 04:56 PM
  5. adding odd numbers
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 09-06-2001, 01:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21