Like Tree1Likes
  • 1 Post By dmh2000

Help me

This is a discussion on Help me within the C Programming forums, part of the General Programming Boards category; Hi ive made a menu for conversions and im not sure how to add the conversions to my menu, i ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    4

    Help me

    Hi ive made a menu for conversions and im not sure how to add the conversions to my menu, i have sub menus: weight, measurement, tempereture and distance, ive done the distance sub menu but cant get my head around doing the kilometres to miles and miles to kilometres conversion, if someone could help i should be able to work the rest out, thanks

    Code:
    #include <stdio.h>
    #include<stdlib.h>
    int menu(void);
    int distance(void);
    int sw;
    int main()
    {
      menu();
    }
    
    
    int menu()
    {
      system("cls");
    
      printf(" Please selcet a catagory !\n");
      printf(" 1.Weight\n");
      printf(" 2.Measurement\n");
      printf(" 3.Tempereture\n");
      printf(" 4.Distance \n ");
      sw = getch();
      sw = sw - '0';
      switch (sw) {
      case 1:
    //weight
        break;
    
    
      case 2:
    //measurment
        break;
    
    
      case 3:
    //tempereture
        break;
    
    
      case 4:
    //distance
        break;
    
    
      default:
        menu();
        break;
      }
    }
    
    int distance()
    {
      system("cls");
      printf(" 1.Mile's to kilometre's\n");
      printf(" 2.Kilomere's to mile's\n");
      printf(" 3.Back to the Main menu\n");
      sw = getch();
      sw = sw - '0';
      switch (sw) {
      case 1:
    //miles to kilometres
        break;
    
    
      case 2:
    //kilometres to miles
        break;
    
    
      case 3:
        main();
        break;
    
    
      default:
        distance();
        break;
      }
    }
    Last edited by Salem; 11-01-2012 at 10:24 AM. Reason: demunged the code

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    that code looks suspiciously like the code from Need help on making a menu system for my program
    since you are copying someone else's work, just copy from that link.
    Salem likes this.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    4
    It is i used it to do the menu but cant figure out how to do the conversions

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    google 'miles to kilometers' etc and it will tell you what to do

  5. #5
    Registered User
    Join Date
    Nov 2012
    Posts
    4
    Ive tried adding a miles to kilometres conversion but cant get it to run properly

    Code:
    #include <stdio.h>#include<stdlib.h>
    
    
    int menu();
    int distance();
    int sw;
    int main()
    {
        menu();
        float value;
        value=distance();
        printf("%f", value);
        return 0;
    
    
    }
    
    
    
    
    int menu()
    {
    system("cls");
    
    
    printf(" Please selcet a category\n");
    printf(" 1.Weight\n");
    printf(" 2.Measurement\n");
    printf(" 3.Distance\n");
    printf(" 4.Tempereture \n ");
    sw=getch();
    sw=sw-'0';
    switch(sw)
    {
    case 1:
    //code....
    break;
    
    
    
    
    case 2:
    //...
    break;
    
    
    
    
    case 3:
    distance();
    break;
    
    
    
    
    case 4:
    //...
    break;
    
    
    
    
    default:
    menu();
    break;
    }
    }
    int distance()
    {
    system("cls");
    printf(" 1.Miles to kilometres\n");
    printf(" 2.Kilomeres to miles\n");
    printf(" 3.Return to the Main menu\n");
    sw=getch();
    sw=sw-'0';
    switch(sw)
    {
    case 1:
    MtoK();
    break;
    
    
    
    
    case 2:
    //code...
    break;
    
    
    
    
    case 3:
    main();
    break;
    
    
    
    
    default:
    distance();
    break;
    }
    }
    int MtoK()
    {
    float miles, kilometres;
    system("cls");
    printf("\t\tMiles to Kilometres Conversion\n");
    printf("\t\t------------------------------\n");
    printf("\t\tEnter number of Miles: ");
    kilometres=miles/0.621371192;
    
    
    printf("\t\t%2.2f mile(s) == %2.2f kilometre(s)",miles, kilometres);
    printf("\n\n\tPress enter to return to the Main Menu");
    getchar();
              return kilometres;
    }

  6. #6
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    595
    Line 106--> what is miles value? You need to properly initialize it. As of right now miles holds some outrageous random value that was in that memory slot.

Popular pages Recent additions subscribe to a feed

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21