I understand the structure of a do while; however, when I start plugging in my statements, I am not gettng the result I want.
The logic is wrong. Knowing the general form of the do while is:
do
statements
while (condition)
and wanting to write a do while code to find out if a number is prime I entered this into the complier:
int input_number2 = 0; //user input number for do-while loop
int mod_number2 = 0; ////modulus number for do-while loop
int ctr_number = 0; ////counts factor
int i = 0;
do
{
cout << \nPlease enter a number";
cin >> input_number2;
ctr_number = 0;
i= input_number2;
i++;
}
while(mod_number2 = i%1);
{
if(mod_number2<=2)
{
cout <<"\nYour number is prime";
}
else{
(mod_number2>2);
cout <<"\nYour number is not prime";
}
}
return 0;
}
Well it does not work. I am not sure of what to do with the counter. I was able to understand it while writing this code as a for loop; but, not as a do while. Any advise is always appreciated.