please help cant get program to work!

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

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

int main(void)

{

int digval, revdigval, answer;
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");
scanf(" %c",&menu);


switch(toupper(menu))
{
case 'A': do {

revdigval=digval%10;
printf("%d",revdigval);
digval = digval/10;
answer= digval+revdigval;
printf("%i\n", answer);
} while(digval>0);
break;

case 'B':do
{

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

break;

case 'D': do
{
revdigval=digval%10;
printf("%d",revdigval);
digval = digval/10;
answer= digval/revdigval;
printf("%i\n", answer);
} 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;
int addOnesDigit = 0;
cin>>x;

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

cout<<onesDigit;

}while(leftOfDecimal!=0);


cout<<""<<endl;
cout<<addOnesDigit<<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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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<<onesDigit;

}while(leftOfDecimal!=0);


cout<<""<<endl;
cout<<addOnesDigit<<endl;
system("pause");

}
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.