Mar 15, 2014 at 2:01pm UTC
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";
}
Mar 15, 2014 at 2:08pm UTC
You never initialize max.
max = 0;
a = max; // a = 0
else
b = max; //b = 0
I'm guessing you meant max = a; max = b;
Mar 15, 2014 at 2:33pm UTC
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";
}
Mar 15, 2014 at 2:55pm UTC
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 Mar 15, 2014 at 2:57pm UTC
Mar 15, 2014 at 3:09pm UTC
thanks pal :))
Last edited on Mar 15, 2014 at 3:10pm UTC