C++ (show biggest number)

Hello guys, i'm new at this forum, and i am counting on your help.

I got a homework to do.

So the problem is, i must create C++ function (or dont know how it's called)

User must enter 3 numbers, and programm must show the biggest one of them.

So far i got here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <conio.h>
#include <stdio.h>
#include <iostream.h>

void main()
{
float x,y,z;
cout<<"Ievadi x vertibu: "; cin>>x;
cout<<"Ievadi y vertibu: "; cin>>y;
cout<<"Ievadi z vertibu: "; cin>>z;
if (x>y,x>z){
cout<<" Lielakais skaitlis ir "<<x;
}
if (y>x,y>z){
cout<<" Lielakais skaitlis ir "<<y;
}
if (z>x,z>y){
cout<<" Lielakais skaitlis ir "<<z;
}
getch();
}



Problem is , when i enter numbers like 4,2,1 (x,y,z) it shows that 4 is the biggest, but also it shows that 2 is the biggest, because it's bigger than 1. Sorry for my english guys, im totally new to C++, started IT programme few days ago. Thanks for your help!
Last edited on
In your if clauses, you use the comma operator. That will just return the last evaluation. You really want to use the "and" operator (&&). So your first check will be if ((x > y) && (x > z)) (I really like the extra parentheses to be explicit about the order of evaluation.)

By the way, in future posts, please use code tags. click on the "<>" button in the Format options and paste your code between the tags that are generated. This makes it easier for the reader to understand and make references to your code.
Thanks for your help Doug. Problem solved.
Topic archived. No new replies allowed.