trying to reverse inputted number then do operation depending on choice of menu and display!

#include<stdio.h>
#include<ctype.h>

int main(void)

{

char a, b, c, d, e, menu;

puts(" Please input a value with 5 numbers or less\n ");
scanf("%i", &digval);

printf("Value is %i\n", digval);

do
{

printf("Menu\n A.) Add reverse\n B.) Subtract reverse\n C.) Multiply reverse\n D.) Divide reverse\n");

{
case 'A': do {

revdigval=digval%10;
printf("%d",revdigval);
digval = digval/10;
} while(digval>0);
break;

case 'B':do
{

revdigval=digval%10;
printf("%d",revdigval);
digval = digval/10;
} while(digval>0);
break;
case 'C':
do
{
revdigval=digval%10;
printf("%d",revdigval);
digval = digval/10;
} while(digval>0);

break;

case 'D': do
{
revdigval=digval%10;
printf("%d",revdigval);
digval = digval/10;
} while(digval>0);

}

}
while(digval>0);
//do
//{
// b=a%10;
// printf("%d",b);
// a = a/10;
//}
//while(a>0);

getchar();
getchar();
return 0;

}
this code is in c++, but you might be able to find it helpful. The program reverses a number and then finds the sum of all the digits. Focus especially on the logic to reverse the number although I am pretty sure you have it.

float x;
int leftOfDecimal;
float onesDigit;
cin>>x;

do {
leftOfDecimal = x / 10;
onesDigit = ((x/10)-leftOfDecimal);
onesDigit = (onesDigit*10);
x = leftOfDecimal;

cout<<onesDigit;

}while(leftOfDecimal!=0);

cout<<""<<endl;
system("pause");
}
the logic is the first couple of statements in the do-while loop.
Can you all use code tags, please? Select the code then press the <> button on the right, so it looks like this:

 ``123456789101112131415161718192021`` ``````float x; int leftOfDecimal; float onesDigit; int addOnesDigit = 0; cin>>x; do { leftOfDecimal = x / 10; onesDigit = ((x/10)-leftOfDecimal); onesDigit = (onesDigit*10); addOnesDigit = addOnesDigit + onesDigit; x = leftOfDecimal; cout<

}
I dont see why it would make a difference but ok.
The code tags format the code properly (preserves the indenting) making it easier to read. People who post their question and use the tags will probably get more replies. It also adds the line numbers - making communication easier.

Don't worry I & many others are always asking for this.

Have a good day - Cheers.
Last edited on
Topic archived. No new replies allowed.