Thread: converting script

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    5

    converting script

    OK first off let me say this is a class assignment and I don't expect anyone to do my work for me. Now here is my problem. My assignment is to write a program that takes pounds and ounces and converts them to kilograms and grams. This assignment is not out of my class book so I'm a lil confused. I am looking for either a tutorial or some pointers on how to do this. My script asks first for pounds, then for ounces - no problem there. My thoughts as to how to convert them into kilograms / grams is take pounds*16+ounces. Then i should have X ounces. I then want to take X ounces*28.375(this is how many grams there are per ounce) and I will have the total number of grams converted. However if x ouces equals 786237 I don't know how to output "X lb X oz is equivalent to X Kg Xg"

    If someone can point me to a page that will explain this (to a non-tech savvy person) I would appreciate it!

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    kg = 786237 / 1000;

    grams_remaining = 786237 % 1000;

    The modulus of the first by the second is the remainder from their division.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    5

    no luck

    OK I enetered in the formulas you gave me and I got 6 errors!

    Here is the code, maybe you can tell me what's wrong with it?

    #include <iostream>

    using namespace std;

    int lbs(int lbs);
    int oz(int oz);
    float kg(int kg);
    float g(int g);
    float totalg(int totalg);

    void main(void)
    {
    cout << "Enter pounds ";
    cin >> lbs;
    cout << endl;
    cout << "Enter ounce: ";
    cin >> oz;
    cout << endl;
    cout <<endl;
    cout << lbs << "lb" << oz << "oz is equivalent to" << kg << "Kg" << g << "g";
    return 0;
    }

    float g(int g)
    {
    return totalg % 1000;
    }

    float kg(int kg)
    {
    return totalg / 1000;
    }

    float totalg(int totalg)
    {
    return lbs * 16 + oz;
    }

  4. #4
    Registered User
    Join Date
    Jul 2002
    Posts
    10
    Ok. For starters...

    Code:
    int lbs(int lbs);
    int oz(int oz);
    float kg(int kg);
    float g(int g);
    float totalg(int totalg);
    These are all declaring functions.

    You can't cin >> lbs because lbs is a function.

    EDIT:

    Also just noticed in the body of main(), you aren't calling any of the functions that actually do the work.
    Last edited by Universe; 09-04-2002 at 04:52 PM.

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    5

    only 1 error now

    OK I re-wrote it and I only get 1 error this time. Here is the revised version:

    #include <iostream>

    using namespace std;

    int lbs, oz;
    float totaloz, totalg, kg, g;



    int main(void)
    {
    cout << "Enter pounds ";
    cin >> lbs;
    cout << endl;
    cout << "Enter ounce: ";
    cin >> oz;


    cout << endl;
    cout <<endl;

    totaloz = lbs * 16 + oz;

    totalg = totaloz * 28.375;

    kg = totalg / 1000;

    g = totalg % 1000;

    cout << lbs << "lb " << oz << "oz is equivalent to " << kg << "Kg " << g << "g";
    return 0;
    }


    and here is the error I get:

    --------------------Configuration: Cpp1 - Win32 Debug--------------------
    Compiling...
    Cpp1.cpp
    F:\Cpp1.cpp(24) : error C2296: '%' : illegal, left operand has type 'float'
    Error executing cl.exe.
    Last edited by ryansutton; 09-04-2002 at 05:50 PM.

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Or if you really want it...

    float fmod( float x, float y)
    {
    return x - ( (x/y) * y);
    }
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 04-10-2009, 12:57 AM
  2. Script in games
    By Shakti in forum Game Programming
    Replies: 7
    Last Post: 09-27-2006, 12:27 AM
  3. In a game Engine...
    By Shamino in forum Game Programming
    Replies: 28
    Last Post: 02-19-2006, 11:30 AM
  4. Passing arguments to script.....
    By suwie in forum C Programming
    Replies: 5
    Last Post: 09-25-2004, 11:10 PM
  5. Game structure, any thoughts?
    By Vorok in forum Game Programming
    Replies: 2
    Last Post: 06-07-2003, 01:47 PM