"Spaces between words" are possible but how.

Hello.I have written this code below on how to enter basic data input for students. Unfortunately, spaces between the words I enter (in testing) cause errors in the program.
Here is the program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
                                //BASIC C++ Codes
                                //Francis Darwin Eugenio

#include <iostream.h>
#include <conio.h>


void main(void)
{
  clrscr();
  char name[25];
  cout <<"\nEnter your Name (No Spaces):";cin>>name[25];
  char yrandsec[20];
  cout <<"\nEnter your Year and Section:";cin>>yrandsec;
  int age[3];
  cout <<"\nEnter your Age:";
  cin>>age[3];
  char birthday[20];
  cout <<"\nEnter your Birthday:";cin>>birthday;
  char address[50];
  cout <<"\nEnter your Address:";cin>>address;
  int tel[8];
  cout <<"\nEnter you Telephone No:";
  cin>>tel[8];
  cout<<"\n\nName:"<<name;
  cout<<"\nYr. and Sec:"<<yrandsec;
  cout<<"\nAge="<<age;
  cout<<"\n\Birthday:"<<birthday;
  cout<<"\n\Address:"<<address;
  cout<<"\nTelephone No.:"<<tel;
  getch();
}


Here is the result when I type in the name "Yhelman Gultia"

Enter your Name (No Spaces):Yhelman Gultia

Enter your Year and Section:
Enter your Age:
Enter your Birthday:
Enter your Address:
Enter you Telephone No:

Name:É ↕
Yr. and Sec:helman
Age=0x0012ff30
Birthday:
Address:
Telephone No.:0x0012fec8


Any help is appreciated. Thank you.

PS.The problem can't be solved even if I replaced char with wchar_.

1
2
3
  int age[3];
  cout <<"\nEnter your Age:";
  cin>>age[3];

This is wrong. You must write

1
2
3
  int age;
  cout <<"\nEnter your Age:";
  cin>>age;


With telephone all the same.

To read the whole line along with spaces use

1
2
3
  char yrandsec[20];
  cout <<"\nEnter your Year and Section:";
  cin.getline(yrandsec, 20);

Topic archived. No new replies allowed.