am i using the char variable correctly ?

hello everyone, im very new to CPP.
i have been trying to make a simple I/O code that asks basic questions.
this will not run . i get error messages when running this on CPP droid app at work. anything you guys would change to make this run better? should i use string instead of char? .
again im really new this so sorry for the elementary questions.

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

using namespace std;

int main()

{

char name [13];

cout<<"welcome, what is your name?" << endl;
cin>> name >> endl;

cout<<"hello"<<name<< endl; 

return 0:


}
Here is the correct code.

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

using namespace std;


int main()
{

    char name[13];

    cout << "welcome, what is your name?" << endl;
    cin >> name;
    
    cout<< "hello " << name << endl; 

    return 0;


}


There were some syntax errors. Here in statement return 0: a colon was used instead of a semicolon and you can not use endl with cin cin>> name >> endl;

I would recommend you following a good book and practicing at the same time.
Last edited on
Topic archived. No new replies allowed.