Hi i have strange problem im new in c++

when i compile this program its only show me the C
why?!??


#include <iostream>
using namespace std;
int main ()
{
int a,b,c,max;
a=2;
b=3;
c=0;
cin >>a>>b>>c;
if(a>b)
a=max;
else
b=max;
if(max>c)
cout <<"max";
else
cout <<"C";
}
You never initialize max.
max = 0;

a = max; // a = 0
else
b = max; //b = 0

I'm guessing you meant max = a; max = b;
u mean like this?

#include <iostream>
using namespace std;
int main ()
{
int a,b,c,max;
a=2;
b=3;
c=0;
max=0;
cin >>a>>b>>c;
if(a>b)
a = max; // a = 0
else
b = max; //b = 0
if(max>c)
cout <<"max";
else
cout <<"C";
}
closed account (18hRX9L8)
Like HellfireXP, I think you want it the other way around...
max = a; and max = b.

Also, I think you want to print the variables also, not just the variable name.

Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

int main(void) {
	int a, b, c, max;

	std::cout << "Enter a, b, and c like this: \"a b c\".\n: ";
	std::cin >> a >> b >> c;

	if (a >= b) {
		max = a;
	} else {
		max = b;
	}

	if (max >= c) {
		std::cout << "A or B is the max: " << max;
	} else {
		std::cout << "C is the max: " << c;
	}

	std::cout << ".\n";
	return 0;
}


Also, please use code tags when posting.
Last edited on
thanks pal :))
Last edited on
Topic archived. No new replies allowed.