4 Replies - 960 Views - Last Post: 02 October 2013 - 06:58 AM Rate Topic: -----

#1 zille   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 22-June 13

Simple C++ Coding giving error finding highest and lowest value

Posted 01 October 2013 - 06:53 PM

I have created this simple program but getting error finding the highest and lowest number

#include <iostream>
using namespace std;

int main()
{
    int num[2];
    int sum;
    int average;
    int product;
    int smallest;
    int largest;
    cout << "Input three diffrent integers: ";
    cin >> num[0] >> num[1] >> num[2];
    sum = num[0] + num[1] + num[2];
    average = (num[0] + num [1] + num[2])/3;
    product = num[0] * num[1] * num[2];
    cout << "The sum is " << sum << endl;
    cout << "The average is "<< average <<endl;
    cout << "The product is "<< product <<endl;
    if(num[0] < num[1] && num[0] < num[2] );
    smallest = num[0];
    if (num[1] < num[0] && num[1] < num[2] );
    smallest = num[1];
    if (num[2] < num[0] && num[2] < num[1] );
    smallest = num[2];
    cout << "Smallest is " << smallest<< endl;
    if (num[0] > num[1] && num[0] > num[2] );
    largest = num[0];
    if (num[1] > num[0] && num[1] > num[2] );
    largest = num[1];
    if (num[2] > num[0] && num[2] > num[1] );
    largest = num[2];
    cout << "Largest is " << largest<< endl;

    system ("pause");
    return 0;
}


Can anyone tell me what i missed.

Is This A Good Question/Topic? 0
  • +

Replies To: Simple C++ Coding giving error finding highest and lowest value

#2 GunnerInc   User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 917
  • View blog
  • Posts: 2,358
  • Joined: 28-March 11

Re: Simple C++ Coding giving error finding highest and lowest value

Posted 01 October 2013 - 07:20 PM

What error(s) are you getting?

Just looking at it I see your if's are wrong. Remove the semi colon at the end of your if lines.

wrong:
if (num[0] > num[1] && num[0] > num[2] );


correct:
if (num[0] > num[1] && num[0] > num[2] )


http://www.cplusplus...torial/control/
Was This Post Helpful? 2
  • +
  • -

#3 EnderW   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 30-September 13

Re: Simple C++ Coding giving error finding highest and lowest value

Posted 01 October 2013 - 07:38 PM

GunnerInc is correct. Your if statements should look more like:
if ( condition ) 
{
[indent]statements[/indent]
}

Was This Post Helpful? 1
  • +
  • -

#4 EnderW   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 30-September 13

Re: Simple C++ Coding giving error finding highest and lowest value

Posted 01 October 2013 - 07:45 PM

I can't edit my posts please ignore the '
' and the '
'

Dang it!
Ignore the '[.indent]' and the '[./indent]'
Was This Post Helpful? 0
  • +
  • -

#5 zille   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 22-June 13

Re: Simple C++ Coding giving error finding highest and lowest value

Posted 02 October 2013 - 06:58 AM

Thank you everyone for support.
Removing the ; end of if statement fix the problem.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1