dev c++ - Dev C++ program closes immediately when entering letters -


my program closes when enter letter. shows rest of code not enter other parts of it. program closes when entering letters remains when entering numbers, until part program supposed show copied information. have tried putting getchar(); after every cin<<a; skips lines , enter few info. here code: * extreme newbie, far longest code i've ever worked on.

 #include <iostream>   #include <stdio.h>   #include <stdlib.h>   #include <string>  using namespace std;  int main()  {  string a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,y,z;  cout<<"enter name:"; cin>>a;   cout<<"enter gender:"; cin>>z;  cout<<"enter age:"; cin>>b;  cout<<"enter address:"; cin>>c;  cout<<"enter school:"; cin>>d;  cout<<"enter nickname:"; cin>>e;  cout<<"enter highest educational attainment:"; cin>>f;  cout<<"what skills?:"; cin>>g;  cout<<"how many years experience have in field?:"; cin>>h;  cout<<"what kind of people have in workplace?:"; cin>>i;  cout<<"what values have?:"; cin>>j;  cout<<"what bad values have?:"; cin>>k;  cout<<"when birthday?:"; cin>>l;  cout<<"what father's name?:"; cin>>m;  cout<<"what mother's name?:"; cin>>n;  cout<<"do have children?:"; cin>>o;  cout<<"what eye color?:"; cin>>y;  cout<<"what dislike?:"; cin>>p;  cout<<"how many in family?:"; cin>>q;  cout<<"what favorite food?:"; cin>>r;  cout<<"your name is:"<<a<<endl; cout<<"you a:"<<z<<endl;    cout<<"you are"<<b<<cout<<"years old."<<endl; cout<<"you live in:"<<c<<endl; cout<<"you studied in:"<<d<<endl; cout<<"your nickname is:"<<e<<endl; cout<<"your highest educational attainment is:"<<f<<endl; cout<<"your skills are:"<<g<<endl; cout<<"you have"<<h<<cout<<"years of experience in field."<<endl; cout<<"you have"<<i<<cout<<"in workplace."<<endl; cout<<"the thing is, are:"<<j<<endl; cout<<"the bad thing is, also:"<<k<<endl; cout<<"your birthday in:"<<l<<endl; cout<<"your father is:"<<m<<endl; cout<<"your mother is:"<<n<<endl; cout<<"you have"<<o<<cout<<"children."<<endl; cout<<"you have"<<y<<"eyes."<<endl; cout<<"you dislike:"<<p<<endl; cout<<"you are"<<q<<cout<<"in family"<<endl; cout<<"your favorite food is:"<<r<<endl;    return 0;  system ("pause");   } 

*edit: replaced float string , added #include <string> @ start of code. problem program closing when supposed show output , when entering space in input next questions in 1 line.

if x float type or integer type

std::cin >> x; 

reads no letter std::cin if std::cin starts character cannot prefix float or integer type.

so x remains 0 , input stream remains unchanged.

for next

std::cin >> y; 

with y of type float or integer, same behavior occurs: y remains 0 , input stream std::cin still starts character cannot read float or integer type.

this behavior goes on until end of program.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -