1. input a number
2. square the number and subtract 23 from it
3. store this as the reference number
3. for all numbers (integers) greater than 1 test whether it will divide evenly into the reference
4. if it does then display the number
5. continue looping up to square root of the reference.
Hmmm ok so i did something... but its not working well...
mainly when i want to enter the number n or m its not working properly as in it accepts numbers which are over 1000
it fixes itself if i turn the signs to the other side but my professor said that i should do it this way. Im not sure where excately the mistake is.
#include <iostream>
#include <cmath>
usingnamespace std;
int i, j, k, q, m;
double s;
int main () {
do{
cout<<"Enter number n [1-1000]:"<<endl;
cin>>i;}
while((i>=1) && (i<=1000));
j=(pow(i,2)-2);
cout<<"n^2-3 is:"<<j<<endl;
do{
cout<<"Enter number m, which will be squared and then used as a divisor [2-1000]:"<<endl;
cin>>m;}
while ((m>=2) && (m<=1000));
q=pow(m,2);
s=j/q;
if (s==int()) {
cout<<"Number "<<j<<" is divisible with the squared number "<<m<<endl;}
else{
cout<<"Number "<<j<<" is not divisible with the squared number "<<m<<endl;}
return 0;
}
Your do...while loop from lines 9 - 12 doesn't look right. It will continually loop for as long as the condition (i>=1) && (i<=1000) is true. In other words, it will keep asking the user to input a value, until the user enters a value that's outside the range 1 - 1000, at which point it will proceed to use that value.