i need my output to display both names of people who inputted the word "Fairytale" under UrType variable instead of only reading the last loop. i know i got lost somewhere but dont know where exactly
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class Oz
{
private:
string urType;
string urTypeN;
public:
void getOzDetails()
{
int count = 1;
while (count<=2)
{
count = count+1;
cout <<"Please enter your name?";
cin>>urTypeN;
cout<<"Do you believe in Fairytales or you Realistic?";
cin>>urType;
}
}
string dreamers()
{
int count = 1;
while(count<=2)
{
count =count + 1;
if(urType !="Fairytales")
{cout<<"Not a believer";}
else
{cout<<"Name: "<<urTypeN;}
}
return 0;}
};
int main()
{
Oz el;
el.getOzDetails();
el.dreamers();
#include <iostream>
#include <string>
#include <iomanip>
usingnamespace std;
class Oz
{
private:
string urType;
string urTypeN;
public:
void getOzDetails()
{
int count = 1;
while (count<=2)
{
count = count+1;
cout <<"Please enter your name?";
cin>>urTypeN;
cout<<"Do you believe in Fairytales or you Realistic?";
cin>>urType;
}
}
string dreamers()
{
int count = 1;
while(count<=2)
{
count =count + 1;
if(urType !="Fairytales")
{
cout<<"Not a believer";
}
else
{
cout<<"Name: "<<urTypeN;
}
}
return 0;
}
};
int main()
{
Oz el;
el.getOzDetails();
el.dreamers();
}
Secondly it's not clear (to me) what you're trying to achieve, therefore, it's not clear what is going wrong. Could you describe, in human language, the actual requirement as well, not just what you think is wrong, but what you're trying to do with the code you posted.
I am trying to get all the names of people who inputed "Fairytales" in the loop of 2 instead of the code reading only the last line. So lets assume that both inserted Fairytale and the
Okay, you need to store the input. At the moment you're overwriting the first input with the second. You have many choices, for this.
Use 2 variables, concatenate the inputs, use a container, etc. I'll show an example below, using a native array. This example is simple and complete, but is not how you should do it. I imagine you're learning, and in time will figure out better ways of doing it, I just don't want you to think this is the recommended way, and at the same time, I don't want to bore you with long explanations of features you haven't learnt yet...
Also, you're returning 0 from a function that is expected to return a string - and you don't use the return value anyway, so I got rid of that.