7 Years
Discussion Span
Last Post by Vusumuzi

I'm not certain I'm following you, here; you should be able to nest any sort of loop inside of any other loop, and there's no need for an if() statement.

Can you explain just what you're trying to accomplish? I can hazard a few guesses as to what you might want, but it would make things much easier if you could explain your intentions, rather than asking for a specific mechanism.

On a hunch, it sounds like what you want is to have a loop which gets broken somewhere other than the loop conditional. If so, then you would indeed want (not necessarily need, but it would be a very limited case otherwise) to use an if() statement controlling a break statement. But as I say, that's just a guess - without knowing your specific intentions, I can't give a specific answer.


I have figured that much. I'm glad you back. Why on earth would this not go ans execute on the main function? Unfortunately it give no errors. It just keeps asking me the gender.

// Assignment 2 Question 5a
#include <iostream>
using namespace std;
// The required function inputAndValidate should be inserted here.
void inputAndValidate (char& sex, int& yearMark, int& examMark){

do { cout << "Please enter gender: " << endl;
cin >> sex;}
while (sex != 'm' || sex != 'f');


int main( )
int yearMark, examMark;
char sex;
inputAndValidate(sex, yearMark, examMark);
cout << "This student is ";
if (sex == 'm')
cout << "male and has a year mark of";
cout << "female and has a year mark of ";
cout << yearMark << " and an exam mark of "
<< examMark << endl;
return 0;

The conditional of the while() loop is incorrect. You want and AND operator (&&) there, not OR.

Schoil-R-LEA you're a beauty! I cant believe I it it was just that one minor thing. thank you.

By the way there was a question I asked a moment ago, do you mind responding to that?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.