pls help

hi I need help.
''C++ basic Program" i want to write a program to read and display the user's name.?
the user can type a maximum of 30 characters including spaces.
What sort of help you need will depend on how much you already know. Perhaps a starting point is the tutorial on Basic Input/Output in C++
http://www.cplusplus.com/doc/tutorial/basic_io/

It will help us to help you if you can show the code you have tried so far.
#include <stdio.h>

void main(void)
{
char name[];

printf("Enter User Name :");
scanf(&name);
clrscr();
printf("User Name is %s", name);
}
this is all I got so far,but it does not work
That code looks like C rather than C++. (though much of C is also valid in C++ too).

However, the original question says, "the user can type a maximum of 30 characters including spaces" which means the character array name must be at least 31 characters in length. Your code doesn't specify a length, which is not valid code.

Also the scanf() function, just like printf(), uses a format string to tell it how to interpret the other parameters, but you've missed that out.
http://www.cplusplus.com/reference/cstdio/scanf/

One more thing, it should be int main() rather than void main().
Even though you have been given limited functionality due to spamming, double posting, and thread hijacking I agree with Chervil. That code is C and not C++, so I'll post both code. Your code is invalid, as Chervil pointed out. It should be:
C:
1
2
3
4
5
6
7
8
9
10
11
12
#include <stdio.h>

int main()
{
      char name[31];

      printf("Enter User Name: ");
      gets(name, 31, stdin);
      printf("User Name is %s", name);
      
      return 0;
}

C++:
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <string>

int main()
{
      std::cout << "Enter User Name: ";
      std::string name;
      std::cin >> name;
      std::cout << "User Name is " << name;

      return 0;
}
Topic archived. No new replies allowed.