Thread: converting meausements

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    6

    Question converting meausements

    Call By Reference and Call By Value

    i have to write a program to convert inches and feet to meters and centimetres and the other way also. My friend said he is doing it using and if else statement a loop to repeat ive tryed it my own way but cant get it to work :/ any ideas on how to do this can functions be used?

    Code:
    
    
    Code:
    /* Program to convert length to different units*/ 
    #include<stdio.h> 
    int main(void) 
    { 
        float length, converted, measure; 
        char inUnits, outUnits; 
             
            printf("Enter the value of length to be converted: "); 
            scanf("%f", &measure); 
             
            printf("Enter the unit of value entered (I, F, C, or M): "); 
            scanf("%c", &inUnits); 
             
            printf("Enter the unit to convert value to (c, m, f, or i ): "); 
            scanf("%c", &outUnits); 
             
            switch(inUnits){ 
                case 'I': 
                    converted = measure * 2.54001; 
                    printf("The length you entered in inches is equal to %f centimeters", converted); 
                    break; 
        
                case 'M': 
                    converted = measure * 3.3; 
                    printf("The length you entered in meters is equal to %f feet", converted); 
                    break; 
                case 'F': 
                    switch(outUnits){ 
                    
                    
                    default: 
                        printf("Incorrect unit entered.  Please enter a valid unit."); 
                        break;} 
                    break; 
                    default: 
                        printf("Incorrect unit entered.  Please enter a valid unit."); 
                        break;} 
                     
             
                        return 0; 
                        }

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Presumably the conversion factor needed depends both on the input units and output units. You code only shows dependence on input units.

    Then, if you want to repeat the process, add a loop construct.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting from wma to mp3
    By yaku in forum C Programming
    Replies: 7
    Last Post: 06-25-2012, 01:12 PM
  2. Help converting!!!
    By giggleboo in forum C++ Programming
    Replies: 2
    Last Post: 12-15-2010, 07:35 AM
  3. Converting exe to DLL
    By jamez05 in forum Windows Programming
    Replies: 0
    Last Post: 10-11-2005, 12:17 PM
  4. converting hex to dec
    By jibbles in forum C Programming
    Replies: 20
    Last Post: 08-07-2004, 11:40 PM
  5. Converting .exe to .cpp or .c
    By OmnipotentCow in forum C Programming
    Replies: 10
    Last Post: 06-19-2003, 12:52 PM