Help solving this problem

• 05-11-2008
marcelomdsc
Help solving this problem
Given the declarations:
int n;
char ch1;
char ch2;

and given that n contains a two-digit number, translate n into two single characters such that ch1 holds the higher-order digit, and ch2 holds the lower-order digit.
For example, if n=59, ch1 would equal '5', and ch2 would equal '9'. Then output the two digits as characters in the same order as the original numbers.
(Hint: Consider how you might use the / and % operators in your solution)

Any ideas? Thanks.
• 05-11-2008
Oldman47
. .. so the hint is given, what can you do with it?

Code:

```     int n=64;     short a=(n%?)/?;     short b=(n%?);```
Figure that out and your output is 6, 4.
• 05-11-2008
Salem
• 05-12-2008
marcelomdsc
...
thanks Oldman47, I couldn't exactly understand how you were trying to solve it but what I ended up doing worked...here is the solution in case you wanna know...
int n;
char ch1;
char ch2;

n = 27;
ch1 = n / 10 + '0';
ch2 = n % 10 + '0';

cout << ch1 << ch2;

Salem- get something better to do.
• 05-12-2008
medievalelks
Quote:

Originally Posted by marcelomdsc
Salem- get something better to do.

Something better than your homework, hopefully.
• 05-12-2008
Salem
Well I won't be wasting any more time reading the same thing on multiple forums.
• 05-13-2008
m37h0d
there's even already a thread on this in this forum...from yesterday, though that person gave the impression it was not a HW assignment.