Need some Guidence

This is a discussion on Need some Guidence within the C++ Programming forums, part of the General Programming Boards category; I am trying to have a program take numbers from any base and convert them to any other base. So ...

  1. #1
    Unregistered
    Guest

    Need some Guidence

    I am trying to have a program take numbers from any base and convert them to any other base. So far I can take a decimal to 8 and 16, yet I can't finalize the program to get it to do binary and say 2.
    Thanks for any help.




    #include <stdio.h>
    #include <iostream.h>
    void to_binary(int i);

    int main()

    {


    int i;



    {
    cout << "Enter a number:" << endl;
    cin >> i ;
    dec(cout); // Set output to decimal
    cout << '\\' << i << '\\' << " = " << i;
    oct(cout); // Set output to octal
    cout << " = 0" << i;
    hex(cout); // Set output to hex
    cout << " = 0x" << i << '\n';
    to_binary(i);
    //bin(cout); // Set output to binary
    //cout << " = 0" << i << '\n';

    }
    return 0;
    }


    void to_binary(int n) //recursive function
    {
    int r;
    r = n % 2;

    if (n >= 2)
    to_binary(n / 2);
    putchar('0' + r);
    return;
    }

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    164
    What happends when you run it?
    // Gliptic

  3. #3
    Unregistered
    Guest
    I receive an error for void to_binary(int i);

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    16
    Look at your main() function, you have 4 curly braces, but I only see a need for 2.

    Try changing:
    int main()
    {

    int i;

    {
    cout << "Enter a number:" << endl;
    cin >> i ;
    dec(cout); // Set output to decimal
    cout << '\\' << i << '\\' << " = " << i;
    oct(cout); // Set output to octal
    cout << " = 0" << i;
    hex(cout); // Set output to hex
    cout << " = 0x" << i << '\n';
    to_binary(i);
    //bin(cout); // Set output to binary
    //cout << " = 0" << i << '\n';

    }
    return 0;
    }


    to:

    int main()

    {
    int i;

    cout << "Enter a number:" << endl;
    cin >> i ;
    dec(cout); // Set output to decimal
    cout << '\\' << i << '\\' << " = " << i;
    oct(cout); // Set output to octal
    cout << " = 0" << i;
    hex(cout); // Set output to hex
    cout << " = 0x" << i << '\n';
    to_binary(i);
    //bin(cout); // Set output to binary
    //cout << " = 0" << i << '\n';

    return 0;
    }
    "Where genius ends, madness begins."
    -Estauns

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A little guidence needed
    By Matty_Alan in forum Game Programming
    Replies: 20
    Last Post: 12-17-2008, 06:41 AM
  2. guidence to a program C
    By nurofen in forum C Programming
    Replies: 17
    Last Post: 04-15-2008, 12:50 AM
  3. guidence
    By eldian() in forum C++ Programming
    Replies: 1
    Last Post: 05-20-2003, 10:36 PM
  4. New program, guidence
    By RoD in forum C++ Programming
    Replies: 5
    Last Post: 12-06-2002, 06:36 AM
  5. Homework guidence, very important
    By RoD in forum C++ Programming
    Replies: 4
    Last Post: 12-04-2002, 07:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21