Thread: Determining order of magnitude of user inputed number?

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    8

    Determining order of magnitude of user inputed number?

    We are doing a homework practicing our ability to write our own functions.

    I need to find the order of magnitude of numbers inputted. According to the instructor, the OoM(50) = 1, OoM(100) = 2, OoM(3250)= 3, and so on.

    So essentially, its scientific notation. 50 = 5.0 x 10^1


    I cannot think of a way to code for this... I mean is it the 10th root of each number?
    Hell, I know how to find the OoM on my own, I know how to write a damn function, but I can't figure out a way to solve this

    Here's what I have coded so far:
    Code:
    #include <cstdlib>
    #include <iostream>
    #include <cmath>
    using namespace std;
    
    int OoM(double number);
    /*takes a number inputted by the user and gives the user that number's order
    of magnitude*/
    
    int main(int argc, char *argv[])
    {
        double input_number;
        int result; //result will be the OoM of the number input
        
        cout << "Enter a number to find out it's order of magnitude:" << endl;
        cin >> input_number;
        
        result = OoM(input_number);
        
        cout << "The order of magnitude of " << input_number << " is:" << endl;
        cout << result << endl;
        
        system("PAUSE");
        return 0;
    }
    
    int OoM(double number)
    {
        return (pow(number,(1/10))); 
        // takes a user input number and takes the 10th root
        // returning this in int form gives us the OoM.  Compiler gives warning
        // however we WANT this conversion of double to int because the OoM is always
        // an integer.  The number you may be trying to find the OoM of could be of
        //type double, but it's OoM is always an int.
        
         
    }
    Any help would be appreciated.

  2. #2
    Registered User
    Join Date
    Sep 2010
    Posts
    8
    Nevermind. Its the log of the number inputted..

    Duh... Man this took way too long to figure out.


    Mods please delete.

    Thanks.

  3. #3
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    You don't have to use log functio in math.h(I'm assuming you are...), you can count how many times you can divide by 10 until the result is less than 10.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Working with Nested "Switch Multiple-Selection"
    By MAV_DevWantB in forum C Programming
    Replies: 5
    Last Post: 09-18-2009, 08:05 AM
  2. Determining number of pages in file
    By starkhorn in forum C++ Programming
    Replies: 2
    Last Post: 08-26-2004, 09:53 PM
  3. Prime number program problem
    By Guti14 in forum C Programming
    Replies: 11
    Last Post: 08-06-2004, 04:25 AM
  4. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 08:43 PM
  5. Random Number problem in number guessing game...
    By -leech- in forum Windows Programming
    Replies: 8
    Last Post: 01-15-2002, 05:00 PM