Unknown answer to an Activity

Hi, we had an activity at school days ago about entering a gender and continuously inputting the gender until a specified gender was entered. To be exact, this was the activity:

"Make a code where you input your name and gender and continouously accept until the gender inputted is "female.""

We actually never knew what the right code was, so I was asking what the right code might be. All the codes we tested appeared to have an error stating that c++ cant convert "char*" to "char".

If you need the code we made, this would be it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream.h>
int main()
{
char gender;
char name;
cout<<"Please enter your name";
cin>>name;
cout<<"Please enter your gender: ";
cin>>gender;
if (gender = "female")
cout<<"You are a " << gender << "!";
else
cout<<"Please input your gender again: ";
cin>>gender;
return 0;
}


F.Y.I.: I tried to use the goto statement for the continuous part, but our teacher said not to because she hasn't thought it yet.

Any help would be greatly appreciated.
if you need something to continuously repeat until condition is met you would need a while loop.
i used a string to compare the input value against the word "female".
so if the input string matches the word female the loop ends.

http://cpp.sh/3cvo
Last edited on
Thanks, but she would not accept the code since she hasn't taught string yet. She has only taught us the int and char identifiers only, and, when she gave the activity, she still hasn't thought us about the while loop. Given this info, what would be the expected code?
you would need an array of char and compare that to female.
if you want something to repeat you need some sort of loop.
comparison is ==.
= is assign.
Wow, no wonder that code didn't work. She tends to give activities which are extrememely far from what she has already thought. She hasn't even thought us about arrays. Thanks for the help
Topic archived. No new replies allowed.