#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    2
    Rep Power
    0

    Post c++ number base convert NO functions


    Writing program to convert base 10 to any base between 2-10. First loop I obtained the largest power. The 2nd loop is not giving the correct output. Unsure about the declaration before the 2nd while loop as well. Using 513 as the base 10 number and 5 as the base 5... the output should be 4023. Unable to get results.



    PHP Code:
    // convert.cpp : Defines the entry point for the console application. 
    // convert.cpp : Defines the entry point for the console application.
    #include <iostream>
    using namespace std;

    int main(int argc, char* argv[])
    {
    int num;
    int base;
    int power;
    int quot;
    int rem;


    cout <<"Enter an integer (which is base 10): ";
    cin >>num;

    cout <<"Enter the base you want the integer converted: ";
    cin >>base;

    power = 1;
    while (power <= num)
    {
    power = power * base;
    }
    power = power / base;

    quot = 1;
    while (quot >= 0);
    {
    quot = num / power;
    rem = num % power;
    power = num / base;
    quot = rem / power;
    cout << quot;
    }

    cout <<"The integer entered in base " << base <<" is : " << quot <<endl;


    return 0;
    }
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,625
    Rep Power
    4247
    erm, I think I see a problem here:
    while (quot >= 0); <--- Your loop ends here because of the semicolon
    {
    // all the stuff in the block is not in the while loop!
    }
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo

IMN logo majestic logo threadwatch logo seochat tools logo