Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

need help creating a program using a do while loop that finds a number that is d

ID: 3623872 • Letter: N

Question

need help creating a program using a do while loop that finds a number that is divisible by both 2 and 7 and when cubed exceeds 30000... so it starts at 1 and keeps incrementing until all conditions are met... here's the program I have so far, but it only runs through the program once...

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int number=1,even=0,divby7=0,cube=0;
do
{
number++;
even=number%2;
divby7=number%7;
cube=number*number*number;

}
while(even==0 && divby7==0 && cube > 30000);
cout << "The number is: "<< number << endl;

}

Explanation / Answer

The error is that you need to loop while the conditions are not met, not while the conditions are met.

int number = 1;

do
{
number++;
}
while(number%2 != 0 || number%7 != 0 || number*number*number <= 30000);