Need help urgenlty -please
I'm new to the forum and request help

I need to write code containing a for loop from 1 to 30.everytime the loop is executed, the answers of one respondent to each of the 3 questins, should be inputed - Q1. how old are you, Q2, what is your gender. Q3 which of the following types of tv programs do you watch most often(choose one of N: News, S:Sport; M:Movies; E: Educational documentaries, O:Other and X: I do not watch Tv.
Validate the asnwer to Q2 using a do..while statement - you should threfore keep asking the person what his or her gender is until M or F is input.

The code has to compute four totals:
How many women older than 30 years do not watch TV at all
How mant women indicate M for their favourite
how many people younger than 20 years indicate S for their favourite
and how many men older than 35 years indicate S for their favourite.

They say - I need to initialise 4 totals
for loop over 30 people
input answer to Q1
input answer to Q2 and validate it usina do..while statement
input answer to Q3
a block of nested ifs where the correct total is incremented
display the four totals

I have started the code but got stuck with the do..while statement -
see code beloe:

#include <iostream>
using namespace std;
int main ()
{
int age;
char gender;
cout << " How old are you: ";
cin >> age;
cout << " Age is " << age << endl;

//for(int i = 0; i <= 3; i++)
//{
do
{
cout << " What is your gender? (M for Male, F for Female)";
cin >> gender;
if (gender != 'M' && gender != 'm')
{cout << " Enter  (M for Male, F for Female)";
cin >> gender;}
}
while ( gender != 'M' && gender == 'm'); // || gender != 'F' && gender != 'f');
//cout << " Gender is " << gender <<endl;

// }
return 0;
}

Try this:

char gender ;
cout << " What is your gender? (M for Male, F for Female)" << flush ;
cin >> gender ;
while ( gender != 'M'
&& gender != 'm'
&& gender != 'F'
&& gender != 'f' )
{
cout << " Please enter M for Male or F for Female: " << flush ;
cin >> gender ;
}

OR this:

char gender = 'x' ; //to make it enter the loop.
while ( gender != 'M'
&& gender != 'm'
&& gender != 'F'
&& gender != 'f' )
{
cout << " What is your gender? (M for Male, F for Female)" << flush ;
cin >> gender ;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.