I'm a beginner and having problems with my code I don't quite understand. The first option in my switch menu is not working and I have tried numerous tweaks to no avail. I've removed the if else statement, altered the "second" variable between constant = 0 and not constant, a few other things as well.
This code is supposed to reverse the digits in an integer. If the integer is less than 10, i.e. 2, the 2 becomes 20. I'm not achieving anything close to that.
cout << "Please enter a number between 0 and 99\n";
cin >> num;
if (num < 9)
num *= 10;
else
num += 0;
while (num !=0)
{
remainder = num%10;
second = remainder*10 + remainder;
num /= 10;
}
cout << num << " reverses to make " << second << endl;
Aucun commentaire:
Enregistrer un commentaire