well here is my problem i had a task to transfrom sequence of decimals entered by user to binary so i did it but here comes my problem it turn out that i MUST have used at least 2 functions 1 main for input output and 1 which contains the code that solves the problem but this code is a if else statement in a loop which is in another loop and i just dont know how realize that in another function so it would use the input from the main and then does the transformation and then comes back to main again and prints the result from this other function ... so i need help ASAP because my deadline is soon, hope someone here would help me so the code :
#include<iostream>
using namespace std;
int main()
{
int dec, len;
string bin;
cout << "Please enter a decimal number(if you want to exit the program enter 0 value) : " << endl;
while(cin >> dec)
{
if (dec==0) break;
bin = "";
while (dec != 0)
{
if (dec % 2 == 0)
bin.insert(0, "0");
else
bin.insert(0, "1");
dec = dec / 2;
}
cout << "The equivalent binary number is: " << bin << endl << endl;
}
}
P.S. and the worst is that they gave us this task before explaining the functions :S