Thread: problem with metric to english conversion

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    2

    problem with metric to english conversion

    I am a c student and can't seem to figure out this Metric conversion program. It reads. Write a program that will assist the user with metric conversions. Your program should allow the user to specify the names of the units as a string(ie meters, liters, kilograms for metric and inches, quarts, pounds, feet for english) and should respond to simple questions such as
    "How many inches are in 2 meters?"
    "How many liters are in 10 quarts?"

    and it should recognize invalid conversions such as

    "How many feet ar in 5 kilograms?'

    Any help would be greatly appreciated!!!!!!!!

  2. #2
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Posts
    236
    The first answer you're likely to get is "Post some code", so post some code.

    I find it easier to work on code if I write myself a little framework first. I break it down into components, such as input, processing and output. Then I break down each of those parts like - Input .. prompt user, read info, break down input to useable chunks. Once I've done that I write code. If you grab a pen and paper it would take you about two minutes to write a framework. It will help you keep focussed, and once you have an attempt, even if it doesn't work well or at all, people here will be very helpful.
    Demonographic rhinology is not the only possible outcome, but why take the chance

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    2
    I guess I am not advanced enough to use this board.

  4. #4
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Posts
    236
    I hope I didn't over complicate things or give you the wrong impression in my post. It's just that this really is a help board, not a "do for you" board. If you make a start people will help. If you're a C student this doesn't look like an assignment that would be given with no grounding in the concepts required, I would imagine you'd be able to write some of the code, once you've written something post it in this thread, remember to use code tags, help will be forthcoming.
    Demonographic rhinology is not the only possible outcome, but why take the chance

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Big hint
    Code:
    #include <stdio.h>
    
    int main ( void ) {
        char buff[BUFSIZ];
        char from[BUFSIZ],to[BUFSIZ];
        int  howmany;
        while ( fgets( buff, BUFSIZ, stdin ) != NULL ) {
            if ( sscanf( buff, "How many %s are in %d %s", from, &howmany, to ) == 3 ) {
                printf( "converting %d from %s to %s\n", howmany, from, to );
            } else {
                printf( "I don't understand\n" );
            }
        }
        return 0;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  2. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 11:31 PM
  3. Configurations give different results
    By Hubas in forum Windows Programming
    Replies: 2
    Last Post: 04-11-2003, 11:43 AM
  4. simple currency conversion problem
    By sweetgem in forum C++ Programming
    Replies: 2
    Last Post: 08-01-2002, 12:41 PM
  5. Replies: 2
    Last Post: 02-07-2002, 09:39 AM