taking 1 interger away and then checking if divisle by certain numbers

I am asked to do this
"Ask the user to enter an integer greater than 1000. Remove the final digit. If the resulting integer is evenly divisible by 3 or 5 or 9, divide it modulo by 7 and add the result into a variable named special, otherwise divide it modulo by 8 and add the result into a variable named normal."


my code
#include <iostream>
using namespace std;

int main()
{
int number, newnumber;
double finalnumber,special, normal;
cout << "Please enter a number greater than 1000." << endl;
cin >> number;
newnumber = number / 10;
if (newnumber % 3 == 0 || newnumber % 5 == 0 || newnumber % 9 == 0)
{finalnumber = newnumber % 7;
special = finalnumber;
}
else
{finalnumber = newnumber % 8;
normal = finalnumber;

}

cout << finalnumber << endl;
return 0;
}




what am i doing wrong? im getting whole intergers for answers that make no sense.
If you want your program to return a decimal number (eg: 3.25145), you should look into using floating point variables. :)
it doesnt even return the right number though. if i put it 1100 it gives me 5.
Last edited on
What would be the correct answer for 1100 then?
removing the final digit gives 110
110 is evenly divisible by 5, so you divide it by 7 and take the remainder, which is 5...

So it seems correct to me :P
Topic archived. No new replies allowed.