Im new to C++, and need help.

Dec 18, 2012 at 3:58am
I am very very new to C++ and need some help with this code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int name;
    cout << "Whats your name?";
    cin >> name;
    
    int final;
    cout << "You're:" << name << endl;

    
    system("PAUSE");
    return EXIT_SUCCESS;
}

Since I am new, I am trying to make this tell you your name, however it outputs random numbers. Help?
Last edited on Dec 18, 2012 at 4:00am
Dec 18, 2012 at 4:14am
closed account (18hRX9L8)
Use main() for this program.

Also, name is an string, not an integer. There for instead if int name; put string name;.

You don't need int final because it is a waste of space and your program takes up un-needed memory. It is like drawing a box and not using it and it takes up space in your attic.

Also, you don't need return EXIT_SUCCESS because the program is already done.

Finally, make sure you put endl; at the end of your c-outs so a line is skipped and your program looks neater and user-friendly. cout<<"What is your name?"<<endl;

So here is the final code:

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
using namespace std;

main()
{
     string name;
     
     cout<<"What is your name?"<<endl;
     cin>>name;
     cout<<"You name is: "<<name<<endl;
     system ("PAUSE");
}



Also, if you go to the documents on this website, they teach you how to use functions, etc... it help a lot.
Last edited on Dec 18, 2012 at 4:18am
Dec 18, 2012 at 4:35am
Thanks! This question was pretty stupid, I am going to assume. Thanks!
Dec 18, 2012 at 4:38am
closed account (18hRX9L8)
No, when everyone started, they were on the level you are on now. Just keep plowing ahead and good luck!
Topic archived. No new replies allowed.