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.

uhh it seems like your just posting every question from an assignment...what are YOUR ideas to begin with?

EDIT: I apologize, I didn't mean for that to sound harsh, I just want to ensure that you are learning as well, because that is what matters most. It is always best for you to explore the concepts first before appealing for help, and then when you do, let us know what your thought process has been...That way we can help you better (in terms of developing problem solving skills), and also ensure that you are understanding and making an honest effort. I think in a previous post you mentioned you didn't know how the forum runs. One of the tenants is that we are not here to do your homework for you, but to help you along. :)

uhh it seems like your just posting every question from an assignment...what are YOUR ideas to begin with?

EDIT: I apologize, I didn't mean for that to sound harsh, I just want to ensure that you are learning as well, because that is what matters most. It is always best for you to explore the concepts first before appealing for help, and then when you do, let us know what your thought process has been...That way we can help you better (in terms of developing problem solving skills), and also ensure that you are understanding and making an honest effort. I think in a previous post you mentioned you didn't know how the forum runs. One of the tenants is that we are not here to do your homework for you, but to help you along. :)

Don't worry, I'm used to it, almost everyone 'acts' like that in forums.

Thanks for your concerns, and yes I'm learning.

I know it is always better to explore the concepts first appealing for help, and that's exactly what I did.

If I wanted to just post my homework so that someone else could do it, I would probably try to disguise it, but I'm not, I was just hoping someone could help me instead of giving me a lecture on ethics.

Anyway thanks, someone else pointed me in the right direction in a different forum so i think I can solve it now.

hi,
there is just another solution:

int main(int argc, char *argv[])
{
int n = 59;
char c1, c2;
c1 = n / 10 + 0x30;     //    in ASCII table, dec 0..9 
c2 = n % 10 + 0x30;     //    are in col 3 starting at row 0, so add 30hex
cout << "digits of " << n << " are " << c1 << " and " << c2 << endl;
cout << "ascii of  " << n << " are " << (int)c1 << " and " << (int)c2 << endl;
/** results:
  * digits of 59 are 5 and 9
  * ascii of  59 are 53 and 57
*/
}

krs,
tesu

P.s. may I am allowed to ask what school are you attending, which location?

thanks, I already solved it differently, but I bet your solution works too.

PS: may I as why do you want to know?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.