// ASKISEIS VOITHIMATOS.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string>
#include <iostream>
usingnamespace std;
int main()
{
int tot(0);int sum(0);
int bp; int bg;
int vath=0;
int sinolo(0),over18(0);
string onoma;
getline(cin,onoma);
while ( onoma!= " ")
{
sinolo++;
cin>>bp;
while (bp>20 || bp<0)
{cout<<"lathos proforikos vathmos"<<endl;cin>>bp;}
cin>>bg;
while (bg>20 || bg<0)
{cout<<"lathos graptos vathmos"<<endl;cin>>bg;}
vath=bg*0.7 + bp *0.3;
cout<<onoma<<" "<<vath<<endl;
if (vath>18 )
over18++;
cout<<"grapse onoma"<<endl;
getline(cin,onoma); //problem here
}
if (sinolo!=0)
cout<<over18/sinolo<<" panw apo 18"<<endl;
system("PAUSE");
return 0;
}
the application doesnt request the 'onoma' variable inside the loop (the getline(cin,onoma) command doesnt work)
so at the "while(onoma !=" ")" the variable 'onoma' always appears to be "" and thus the program continues forever...
how can I solve this ?
thank you very much !
"cin extraction stops reading as soon as if finds any blank space character, so in this
case we will be able to get just one word for each extraction. This behavior may or may not be what we want; for
example if we want to get a sentence from the user, this extraction operation would not be useful. "
so the cin will be a bad choise when trying to read a name
however, I have tried it and every time I type a space character and press enter it doesnt move to the next command
actually it does nothing.it just waits for me to type something else,and the in proceeds to check the 'while' condition