Write c++ statements to find a positive value that is divisible by both 11 and 12. Use a while loop.
I am new to c++ please help! thanks
So far this is what I have..
while (choice != 0)
{
cout << "Enter a positive value" << endl;
cin >> inputChar;
input = inputChar.length();
int DigitSum = 0;
for (int a = input - 1; a >= 0; a--)
{
char x = inputChar.at(a);
int y = (x - 48);
if (a % 2 != 1)
{
DigitSum = DigitSum + y;
}
else
DigitSum = DigitSum - y;
}
if (DigitSum % 11 != 0)
cout << "This value is not divisible by 11"<<endl;
else
cout << "This integer is divisible by 11" << endl;
cin >> choice;
}
method 2:
int x;
cin >> x;
if(x%12 == 0 && x%11 == 0)
//then its divisible by both
else
//it isn't
you look like you are close except for the weird user input. Just read directly into an integer if you don't need validation. If you need validation, read into a string and check it.
I can't for the life of me figure out why they want a while loop.
maybe find one with a while loop?! Somewhat silly method 3:
x = 1;
while(x %11 != 0 && x%12 != 0)
x= rand();
So its unclear, are you to find a number or let the user put one in??
then there is no sensible place for a while loop. You just check 11 & 12 and its done.
I suppose you could loop until the user picked on that matched...?
Do you still need some help? You are pretty close to it I think?