So the assignment is to ask for a variable in a certain range the print the individual digits of the numbers with three spaces in between the digit. For example 1234 should print
0 1 2 3 4
1 2 3 4
2 3 4
3 4
4
I’m pretty sure I have most of the assignment done I am just having trouble changing the variable number in my loop. The number sorts itself into the right if statement but then when it loops instead of the number going down a digit (i.e. 2343 to 343) all it does is print the same number 5 times. I have researched in my book and looked online but i’m not seeing it. It’s probably something simple just not sure what. Here’s the code:
#include <stdio.h>
#include <stdlib.h>
void loopingDigitprinter(int digit);
int division(int* digit);
int main()
{
int digitPrint;
printf("Please enter a number between 0 and 32,767: ");
scanf("%d", &digitPrint);
loopingDigitprinter (digitPrint);
return 0;
}
void loopingDigitprinter(int digit)
{
int loopLine= 0;
int thousand;
int hundred;
int original;
original = digit;
while(loopLine < 4)
{
if (digit > 10000 && digit <= 32767)
{
thousand = digit/ 1000;
hundred = digit % 1000;
printf("%02d%03d\n",thousand, hundred);
digit %= 10000;
}
else if (digit < 10000 && digit > 1000)
{
if (original > 10000)
{ thousand = digit/ 1000;
hundred = digit % 1000;
digit %= 1000;
printf("%01d%03d\n",thousand, hundred);
}
else
{
thousand = digit/ 1000;
hundred = digit % 1000;
printf("%02d%03d\n",thousand, hundred);
digit %= 1000;
}
}
else if (digit < 1000 && digit > 100)
{
if (original > 10000)
{
hundred = digit % 1000;
printf("%d\n", hundred);
digit %= 100;
}
else if (original < 10000 && original > 1000)
{
thousand = original / 1000;
hundred = digit % 1000;
printf("%d%d\n",thousand,digit);
printf("%d\n", digit);
digit %= 100;
digit %= 100;
}
else
{
thousand = digit/ 1000;
hundred = digit % 1000;
printf("%02d%03d\n",thousand, hundred);
digit %= 1000;
thousand = original / 1000;
hundred = digit % 1000;
printf("%d%d\n",thousand,digit);
printf("%d\n", digit);
digit %= 100;
printf("%d\n", digit);
digit %= 10;
printf("%d\n", digit);
}
}
else if (digit < 100 && digit > 10)
{
if (original > 10000)
{ hundred = digit % 1000;
printf("%d\n", hundred);
digit %= 10;
printf("%d\n", digit);
}
else if (original < 10000 && original > 1000)
{
thousand = original / 1000;
hundred = digit % 1000;
printf("%d\n",hundred);
digit %= 10;
printf("%d\n", digit);
}
else if (original < 1000 && original > 10)
{
thousand = digit/ 1000;
hundred = digit % 1000;
printf("%02d%03d\n",thousand, hundred);
digit %= 1000;
thousand = original / 1000;
hundred = digit % 1000;
printf("%d%03d\n",thousand,digit);
printf("%03d\n", digit);
digit %= 100;
printf("%d\n", digit);
digit %= 10;
printf("%d\n", digit);
}
else
printf("1");
}
else if(original > 0 && original < 10)
{
printf("0000%d\n", original);
printf("000%d\n", original);
printf("00%d\n", original);
printf("0%d\n", original);
printf("%d\n", original);
break;
}
loopLine++;
}
return;
}
I dont know what you are doing there as i did not read the code.
But do refer to my sample code. It pretty much does the needful