Did you even click the link to read about what indentation means?
Indentation means your code is arranged such that is represents the flow and scope of the code, like this.
Code:
#include<iostream>
using namespace std;
int decimal_to_binary(int decb)
{
int counterb;
int round = 0;
int h[10]; //0-9 means 10 won't forget it again
int limit = 0;
int i;
while (1) {
counterb = 0;
if (decb % 2 != 0) {
counterb++;
} else {
counterb = 0;
}
h[round] = counterb; //Replaced the whole switch
limit = round; //No range change was needed
if (decb <= 1)
break;
decb = decb / 2;
round++;
}
for (i = limit; i >= 0; i--)
cout << h[i];
return 1;
}
int main()
{
int choice;
cout << "Welcome to the value converter" << endl
<< "1.Conversion from decimal to binary ." << endl;
cin >> choice;
switch (choice) {
case 1:
{
int dec;
cout << "Enter the number" << endl;
cin >> dec;
decimal_to_binary(dec);
}
break;
}
return 0;
}
Take your decimal_to_binary() function as an example.
In your poorly indented version, it's impossible to tell whether the for loop is inside or outside of the while loop, without careful counting of the braces.
Whereas with good indentation by a programmer who cares about how the code looks to others, it's instantly obvious that the while loop and the for loop are separate.
Not only does this benefit other readers, it also benefits you as well.
Imagine now that your code was say 10x longer - how much harder would it be to understand what the code is doing?