I started to teach myself to program in C about a month ago. I am only very basic. I was just wondering if anybody would be kind enough to help me write a progam that is part of an excericse sheet I am doing. I just can't do it. Everything I try to do makes my compiler swear (hyperthetically!) at me. If anybody could write it for me I would be extremely gratefu and their will be a prize! WOW!
Please, please please could someone solve the following problem: This is a copy of the problem statement on the excerice shet.
TASK Read a Hexadecimal Number
Write a program to read two charcters, and print their decimal value when interpreted as a 2-digit hexadecimal number.
Accept upper case letters 'A'...'F' for values from 10 to 15.
Print a message containing the word "Error" if either of the characters are not in the set {0..9, A..F}
Input Format
Two characters: hh
Typical input: A3
Output Format
Should be of the form: Hex hh is decimal dd
Typical output: Hex A3 is decimal 163
Notes and Hints
To read 2 characters, use:
char c1, c2;
scanf( "%c%c", &c1, %c2);
To find the "value" of a character, use
if (ch >= '0' && ch <= '9' ) {
value = ch - '0'
}
if ( ch>= 'A' && ch <= 'F' ) {
Value = 10 + ch - 'A';
}
This is probably simple to do but I am a complete newbee, but I will be forever grateful if you could solve it.
Thank you greatly! 🙂
(PM me, if you want to know what the prize is!)
Please, please please could someone solve the following problem: This is a copy of the problem statement on the excerice shet.
TASK Read a Hexadecimal Number
Write a program to read two charcters, and print their decimal value when interpreted as a 2-digit hexadecimal number.
Accept upper case letters 'A'...'F' for values from 10 to 15.
Print a message containing the word "Error" if either of the characters are not in the set {0..9, A..F}
Input Format
Two characters: hh
Typical input: A3
Output Format
Should be of the form: Hex hh is decimal dd
Typical output: Hex A3 is decimal 163
Notes and Hints
To read 2 characters, use:
char c1, c2;
scanf( "%c%c", &c1, %c2);
To find the "value" of a character, use
if (ch >= '0' && ch <= '9' ) {
value = ch - '0'
}
if ( ch>= 'A' && ch <= 'F' ) {
Value = 10 + ch - 'A';
}
This is probably simple to do but I am a complete newbee, but I will be forever grateful if you could solve it.
Thank you greatly! 🙂
(PM me, if you want to know what the prize is!)