Help with loop

I just made this simple program
and I got stuck with the while loop on the "exit?" because of the getline(cin,z2);
I try taking it out but it just does not works... since it takes the enter as an variable value and the code just skips a line...

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <iomanip>
#include <fstream>
#include <string>
#include <sstream>

using namespace std;

int main()
{
    int varinfo=0, varconst=0,x=0,d ;
    string allthings [100][100];
    string Nombres, Edad, Peso, Profesion, Estatura, Genero;
//conversion
    int z =1;
    std::string z2;
    std::stringstream zout;
    zout<<z;
    z2=zout.str();
//while loop
    while(z>0){
    cout<<"What is your Name?"<<endl;
    getline (cin,Nombres);
    allthings[x][0]=Nombres;
    cout<<"Are you male or female?"<<endl;
    getline(cin,Genero);
    allthings[x][1]=Genero;
    cout<<"What is your age?"<<endl;
    getline(cin,Edad);
    allthings[x][2]=Edad;
    cout<<"What is your Proffesion?"<<endl;
    getline(cin,Profesion);
    allthings[x][3]=Profesion;
    cout<<"What is your height (cm)?"<<endl;
    getline(cin,Estatura);
    allthings[x][4]=Estatura;
    cout<<"How much do you weight (lb)?"<<endl;
    getline(cin,Peso);
    allthings[x][5]=Peso;
    cout<<endl;
    cout<<"exit? yes= any key no= 0"<<endl;
    getline(cin,z2);
    cout<<"thank you...";
    cout<<endl;
//in loop statement
    if(z==0){
        cout<<"please fill out the form again..."<<endl<<endl;x++;
        }
    }
//other
ofstream fileoutput("formade.txt");
    fileoutput<<Nombres<<endl<<"You are a:  "<<Genero<<endl<<"Your Proffesion is:  "<<Profesion<<endl<<"You weight: "<<Peso<<endl<<"Your height is: "<<Estatura<<endl;
    fileoutput<<allthings;varinfo++;varconst++;
    fileoutput.close();
//other
    cout<<"What do you want to know about yourself?"<<endl<<"0-5"<<endl;
    cin>>d;
    cout<<allthings[x][d];
    return 0;
}
Last edited on
closed account (28poGNh0)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <iomanip>
#include <fstream>
#include <string>
#include <sstream>
# include <conio.h>
using namespace std;

int main()
{
    int varinfo=0, varconst=0,x=0,d ;
    string allthings [100][100];
    string Nombres, Edad, Peso, Profesion, Estatura, Genero;
//conversion
    int z =1;
    std::string z2;
    std::stringstream zout;
    zout<<z;
    z2=zout.str();
//while loop
    while(z>0){
    cout<<"What is your Name?"<<endl;
    getline (cin,Nombres);
    allthings[x][0]=Nombres;
    cout<<"Are you male or female?"<<endl;
    getline(cin,Genero);
    allthings[x][1]=Genero;
    cout<<"What is your age?"<<endl;
    getline(cin,Edad);
    allthings[x][2]=Edad;
    cout<<"What is your Proffesion?"<<endl;
    getline(cin,Profesion);
    allthings[x][3]=Profesion;
    cout<<"What is your height (cm)?"<<endl;
    getline(cin,Estatura);
    allthings[x][4]=Estatura;
    cout<<"How much do you weight (lb)?"<<endl;
    getline(cin,Peso);
    allthings[x][5]=Peso;
    cout<<endl;
    cout << allthings[x][3] << endl;
    cout<<"exit? yes= any key no= 0"<<endl;
    switch(getch())
    {
        case '0':
        z=0;
        break;
        default : break;
    }
    cout<<"thank you...";
    cout<<endl;
//in loop statement
    }
//other
ofstream fileoutput("formade.txt");
    fileoutput<<Nombres<<endl<<"You are a:  "<<Genero<<endl<<"Your Proffesion is:  "<<Profesion<<endl<<"You weight: "<<Peso<<endl<<"Your height is: "<<Estatura<<endl;
    fileoutput<<allthings;varinfo++;varconst++;
    fileoutput.close();
//other
    cout<<"What do you want to know about yourself?"<<endl<<"0-5"<<endl;
    cin>>d;
    cout<<allthings[x][d];
    return 0;
}
closed account (28poGNh0)
You're welcome
hey Techno01 can you explain what you did here??
just for the sake of knowledge it self
closed account (28poGNh0)
And can you say thanks ?just for the sake of being grateful.
.
.
.
well your while loop dose not gonna end until z being smaller than or equal 0

getch() asks you to enter a caractere ,this caractere will define which case in the switch statment will be excuted when you enter 0 ,you just say assing z to 0 ,
and that's what we're looking for to end the looping

have a nice day
Pretty bad attitude there, Techno01.

Rather than explaining the issue, you throw a bunch of code at the OP and then get ratty when they ask you to explain?

This is a forum. Some people say thanks, some people don't. Deal with it and maybe consider posting a more helpful solution in the future.
Last edited on
Sorry About that... I just notice that I have erased the thank you post by mistake...
I really thank you for that

and I also think that Ihutch105 is right since we are here to learn not just to get the problem solve...

anyhow thank you both :D
closed account (28poGNh0)
Well I am sooooooooooo sorry for my attitude
me too I forget to put :) after ther three points

And we are here to learn not just to get the problem solve...
Topic archived. No new replies allowed.