Whats wrong with this code?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <string>
using namespace std;
int main()
{
    Int a, b,c;
    string j,k;

    j = "a is greater than the b";
    k = "b is greater than the a";

    cout << "enter the value of a: "; cin >> a;
    cout << "\n";
    cout << "enter the value of b: "; cin >> b;

    c= (a>b) ? j:k;

    cout << c;
    return 0;
}


I can't compile it. code::block is showing error.
Usually the compiler will identify the line number where the problem occurs. Take a close look at the error message and then back to your code.
closed account (zb0S216C)
"Int" is not a type.

Wazzak
changed it to int but still problem in the line 6.
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>
#include <string>

using namespace std;

int main()
{
    int a, b;
    string j, k, l;

    j = "a is greater than the b";
    k = "b is greater than the a";

    cout << "enter the value of a: "; cin >> a;
    cout << "\n";
    cout << "enter the value of b: "; cin >> b;

    l = ( a > b ) ? j : k;

    cout << l << endl;

    return 0;
}
Last edited on
Lines 6 and 7 (with int corrected from Int) should compile ok. But there's a problem further down, at line 16 - "cannot convert string to int".

c needs to be a string, not an int.
I got it.. Thank you all .
Topic archived. No new replies allowed.