Question: HELP WITH THIS CODE! I need to make sure when i input the number 0 i get out 0x0. FOr some reason, I am getting

HELP WITH THIS CODE! I need to make sure when i input the number 0 i get out 0x0. FOr some reason, I am getting 0x. Please make sure that the code edit doesn't mess with the rest of the code.

#include using namespace std;

int main() { long int decnum, rem, quot; //variables declaration int i = 1, j, temp; //variables declaration char hexnumber[100]; //variables declaration

cout << "Enter a decimal number: "; cin >> decnum; //reading the decimal number quot = decnum; while (quot != 0) { temp = quot % 16; if (temp < 10) //for converting integer into character temp = temp + 48; else temp = temp + 55;

hexnumber[i++] = temp; quot = quot / 16; } cout << "Your number in hex is 0x"; for (j = i - 1; j > 0; j--) cout << hexnumber[j]; cout <<"."<< endl; return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!