C++ big newbie needs help

C++ big newbie needs help

Post by kirbyman1 on Sat Jan 31, 2009 11:20 pm
([msg=17187]see C++ big newbie needs help[/msg])

#include <iostream>
#include <string>
using namespace std;

int main()
{
double a=0; //initializes a
double b=0; //initializes b
double c=0; //initializes c
cout<<"Enter the first number";
cin>>a;
cout<<"Enter the second number";
cin>>b;
cout<<"Enter the third number";
cin>>c;
cout<<"The average of these values is "<<(a+b+c)/3<<endl;
if ((a>b) && (a>c));
{
cout<<a<<"is the largest double"<<endl;
}
if ((b>a) && (b>c));
{
cout<<b<<"is the largest double"<<endl;
}
if ((c>a) && (c>b));
{
cout<<c<<"is the largest double"<<endl;
}
if ((a<b) && (a<c));
{
cout<<a<<"is the smallest double"<<endl;
}
if ((b<a) && (b<c));
{
cout<<b<<"is the smallest double"<<endl;
}
if ((c<a) && (c<b));
{
cout<<c<<"is the smallest double"<<endl;
}

system("pause");
}







This is supposed to print the max of these doubles and the minimum of these doubles, but instead it just prints all of them.

Why doesn't my code do what its supposed to do?

-- Sat Jan 31, 2009 11:21 pm --

oh crap it took all out my tabbing.

ok guys pretend there's nothing wrong with the tabbing when you look at it.
kirbyman1
New User
New User
 
Posts: 4
Joined: Sat Jan 31, 2009 11:14 pm
Blog: View Blog (0)


Re: C++ big newbie needs help

Post by bird7727 on Sun Feb 01, 2009 12:47 am
([msg=17192]see Re: C++ big newbie needs help[/msg])

You need an else statement to close the ifs.
bird7727
New User
New User
 
Posts: 48
Joined: Sun Feb 01, 2009 12:43 am
Blog: View Blog (0)


Re: C++ big newbie needs help

Post by kirbyman1 on Sun Feb 01, 2009 2:13 am
([msg=17199]see Re: C++ big newbie needs help[/msg])

ok someone helped me guys it was the semicolons causing trouble.
Thanks again.
kirbyman1
New User
New User
 
Posts: 4
Joined: Sat Jan 31, 2009 11:14 pm
Blog: View Blog (0)



Return to C and C++

Who is online

Users browsing this forum: No registered users and 0 guests