Hello, I am new to C++. I am trying to build a program that solves this the bellow problem. I've started it but I'm no sure if this is right.

Please help!

**Problem:**

A Gym Teacher's riddle

A Gym teacher lines up her students in groups and sometimes has lone students, that is, there are students not in any group, given the situations below determine how many students are in the gym teacher's class.

When she lines them up by 2's, there is a lone student

When she lines them up by 3's, there is a lone student

When she lines them up by 4's, there is a lone student

When she lines them up by 5's, there is a lone student

When she lines them up by 6's, there is a lone student

When she lines them up by 7's, there are no left over students.

Hint:

Set up the equality

Let the brute computing force of the computer solve the math for you (e.g., for-loop + if-then).

**Code: **

#include <iostream>

#include <conio.h>

using namespace std;

int main()

{

int num ;

if ( (num % 2 == 1) && (num % 3 == 1) && (num % 4 == 1) && (num % 5 == 1) && (num % 6 == 1) && (num % 7 == 0) )

{

cout << " The number of students is " << num << endl ;

}

getch();

return 0 ;

}

Please help!

A Gym Teacher's riddle

A Gym teacher lines up her students in groups and sometimes has lone students, that is, there are students not in any group, given the situations below determine how many students are in the gym teacher's class.

When she lines them up by 2's, there is a lone student

When she lines them up by 3's, there is a lone student

When she lines them up by 4's, there is a lone student

When she lines them up by 5's, there is a lone student

When she lines them up by 6's, there is a lone student

When she lines them up by 7's, there are no left over students.

Hint:

Set up the equality

Let the brute computing force of the computer solve the math for you (e.g., for-loop + if-then).

#include <iostream>

#include <conio.h>

using namespace std;

int main()

{

int num ;

if ( (num % 2 == 1) && (num % 3 == 1) && (num % 4 == 1) && (num % 5 == 1) && (num % 6 == 1) && (num % 7 == 0) )

{

cout << " The number of students is " << num << endl ;

}

getch();

return 0 ;

}

As the assignment says, you should use a for loop to try all possible values of num. As it stands, you are testing only one time for the uninitialized value of num.

Topic archived. No new replies allowed.