ok so i am suppose to write a program that displays binary and hexadecimal as so 0000 1010 A, but some of my code shows 1C and i dont know how to fix it. please help

/*

*/
#include<iostream>
using namespace std;

int main()
{
	int arr[8];
	char p = '0';
	int k = 0; //keeps track of left side of hex output
	int z = 1; //keeps track of right side of hex output
	//initialize the values in the array to 0
	for(int i=0; i<8; i++)
		arr[i]=0;
	
	
	//outer loop to keep count of iterations
	for(int j=0; j<255; j++)
	{
		//scans the array from the end to search for the first occurring 0
		for (int i=7; i>=0; i--)
			if(arr[i]==0)
			{
				while(i<8)
				{
					if(arr[i]==0)	
					{
						arr[i]=1;
					}
					else
					{
						arr[i]=0;
					}
					i++;
				}
			break;
			}
		//prints each new array
		for (int j=0; j<8; j++)
		{
			cout << arr[j];
			if(j == 3)
				cout << " ";
			
		}
cout << "     ";

if(z > 15)
{
	z = 0;
	if(k < 9)
	{
		k++;
		if(k == 0)
			p = '0';
		else if(k == 1)
			p = '1';
		else if(k == 2)
			p = '2';
		else if(k == 3)
			p = '3';
		else if(k == 4)
			p = '4';
		else if(k == 5)
			p = '5';
		else if(k == 6)
			p = '6';
		else if(k == 7)
			p = '7';
		else if(k == 8)
			p = '8';
		else if(k == 9)
			p = '9';
		cout << k << z;

	}
	else if(k < 10)
	{
		k++;
		p = 'A';
		cout << p << z;
	}
	else if(k < 11)
	{
		k++;
		p = 'B';
		cout << p << z;
	}
	else if(k < 12)
	{
		k++;
		p = 'C';
		cout << p << z;
	}
	else if(k < 13)
	{
		k++;
		p = 'D';
		cout << p << z;
	}
	else if(k < 14)
	{
		k++;
		p = 'E';
		cout << p << z;
	}
	else
	{
		k++;
		p = 'F';
		cout << p << z;
	}
	z++;
}
else
{
//	cout << "THIS IS Z = " << z << endl;
	if(z < 10)
	{
		cout << p << z;
//		cout << "THIS IS Z BEING > 15!!" << endl;
		z++;
	}
	else if(z == 10)
	{
		z++;
		cout << p << "A";
	}
	else if(z == 11)
	{
		z++;
		cout << p << "B";
	}
	else if(z == 12)
	{
		z++;
		cout << p << "C";
	}
	else if(z == 13)
	{
		z++;
		cout << p << "D";
	}
	else if(z == 14)
	{
		z++;
		cout << p << "E";
	}
	else
	{
		z++;
		cout << p << "F";
	}
}
		cout<< endl;
	}
	
	
	
}

Search the forum first. See if that helps. Then ask question if it comes
empty.

Just curious, you have initialized k and z initially and then without any assignments you seem to be checking its value further down, did you intend that and also the binary number does not seem to be input at any stage, was that the intention?

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.