A C Program to used as Weight Converter – IGNOU MCA Assignment 2013

By | September 15, 2013

MASTER OF COMPUTER APPLICATIONS
Course Code : MCS-011
Course Title : Problem Solving and Programming
Assignment Number : MCA(1)/011/Assign/13
Assignment 2013
 An interactive C program called “WEIGHT CONVERTER” that accepts the weight in milligrams / decigrams / centigrams / kilograms /ounces / pounds / tons and displays its equivalent in grams.

 

#include<stdio.h>
void main()
{
  int NUM;
  float WEIGHT,GRAMS;
  clrscr();
  printf("SELECT MEASURING MASS");
  printf("\n 1. MILLIGRAM\n");
  printf("\n 2. CENTIGRAM\n");
  printf("\n 3. DECIGRAM\n");
  printf("\n 4. KILOGRAM\n");
  printf("\n 5. MEGAGRAM(TON)\n");
  printf("\n 6. OUNCE\n");
  printf("\n 7. POUND\n");
  printf("ENTER CHOICE HERE :");
  scanf("%d",&NUM);
  switch(NUM)
  {
    case 1 :    printf("\n SELETED MILLIGRAMS TO GRAMS\n");
        break;
    case 2 :    printf("\n SELETED CENTIGRAMS TO GRAMS\n");
        break;
    case 3 :    printf("\n SELETED DECIGRAMS TO GRAMS\n");
        break;
    case 4 :    printf("\n SELETED KILOGRAMS TO GRAMS\n");
        break;
    case 5 :    printf("\n SELETED MEGAGRAMS(TONS) TO GRAMS\n");
        break;
    case 6 :    printf("\n SELETED OUNCES TO GRAMS\n");
        break;
    case 7 :    printf("\n SELETED POUNDS TO GRAMS\n");
        break;
    default :   printf("YOU HAVE ENTERED WRONG CHOICE !!!");
        goto QUIT;
  }
  printf("ENTER WEIGHT HERE :");
  scanf("%f",&WEIGHT);
  switch(NUM)
  {
    case 1 :    GRAMS=WEIGHT/1000;
        printf("\n %.2f MILLIGRAMS IS %.2f GRAMS\n",WEIGHT,GRAMS);
        break;
    case 2 :    GRAMS=WEIGHT/100;
        printf("\n %.4f CENTIGRAMS IS %.4f GRAMS\n",WEIGHT,GRAMS);
        break;
    case 3 :    GRAMS=WEIGHT/10;
        printf("\n %.4f DECIGRAMS IS %.4f GRAMS\n",WEIGHT,GRAMS);
        break;
    case 4 :    GRAMS=WEIGHT*1000;
        printf("\n %.4f KILOGRAMS IS %.4f GRAMS\n",WEIGHT,GRAMS);
        break;
    case 5 :    GRAMS=WEIGHT*1000000;
        printf("\n %.4f TONS IS %.4f GRAMS\n",WEIGHT,GRAMS);
        break;
    case 6 :    GRAMS=WEIGHT*2835/100;
        printf("\n %.4f OUNCES IS %.4f GRAMS\n",WEIGHT,GRAMS);
        break;
    case 7 :    GRAMS=WEIGHT*45359/100;
        printf("\n %.4f POUNDS IS %.4f GRAMS\n",WEIGHT,GRAMS);
        break;
  }
  QUIT:
    getch();
}

CODE : -

  1. #include<stdio.h>
  2. void main()
  3. {
  4.   int NUM;
  5.   float WEIGHT,GRAMS;
  6.   clrscr();
  7.   printf("SELECT MEASURING MASS");
  8.   printf("\n 1. MILLIGRAM\n");
  9.   printf("\n 2. CENTIGRAM\n");
  10.   printf("\n 3. DECIGRAM\n");
  11.   printf("\n 4. KILOGRAM\n");
  12.   printf("\n 5. MEGAGRAM(TON)\n");
  13.   printf("\n 6. OUNCE\n");
  14.   printf("\n 7. POUND\n");
  15.   printf("ENTER CHOICE HERE :");
  16.   scanf("%d",&NUM);
  17.   switch(NUM)
  18.   {
  19.     case 1 :    printf("\n SELETED MILLIGRAMS TO GRAMS\n");
  20.         break;
  21.     case 2 :    printf("\n SELETED CENTIGRAMS TO GRAMS\n");
  22.         break;
  23.     case 3 :    printf("\n SELETED DECIGRAMS TO GRAMS\n");
  24.         break;
  25.     case 4 :    printf("\n SELETED KILOGRAMS TO GRAMS\n");
  26.         break;
  27.     case 5 :    printf("\n SELETED MEGAGRAMS(TONS) TO GRAMS\n");
  28.         break;
  29.     case 6 :    printf("\n SELETED OUNCES TO GRAMS\n");
  30.         break;
  31.     case 7 :    printf("\n SELETED POUNDS TO GRAMS\n");
  32.         break;
  33.     default :   printf("YOU HAVE ENTERED WRONG CHOICE !!!");
  34.         goto QUIT;
  35.   }
  36.   printf("ENTER WEIGHT HERE :");
  37.   scanf("%f",&WEIGHT);
  38.   switch(NUM)
  39.   {
  40.     case 1 :    GRAMS=WEIGHT/1000;
  41.         printf("\n %.2f MILLIGRAMS IS %.2f GRAMS\n",WEIGHT,GRAMS);
  42.         break;
  43.     case 2 :    GRAMS=WEIGHT/100;
  44.         printf("\n %.4f CENTIGRAMS IS %.4f GRAMS\n",WEIGHT,GRAMS);
  45.         break;
  46.     case 3 :    GRAMS=WEIGHT/10;
  47.         printf("\n %.4f DECIGRAMS IS %.4f GRAMS\n",WEIGHT,GRAMS);
  48.         break;
  49.     case 4 :    GRAMS=WEIGHT*1000;
  50.         printf("\n %.4f KILOGRAMS IS %.4f GRAMS\n",WEIGHT,GRAMS);
  51.         break;
  52.     case 5 :    GRAMS=WEIGHT*1000000;
  53.         printf("\n %.4f TONS IS %.4f GRAMS\n",WEIGHT,GRAMS);
  54.         break;
  55.     case 6 :    GRAMS=WEIGHT*2835/100;
  56.         printf("\n %.4f OUNCES IS %.4f GRAMS\n",WEIGHT,GRAMS);
  57.         break;
  58.     case 7 :    GRAMS=WEIGHT*45359/100;
  59.         printf("\n %.4f POUNDS IS %.4f GRAMS\n",WEIGHT,GRAMS);
  60.         break;
  61.   }
  62.   QUIT:
  63.     getch();
  64. }

SCREEN SHOTS :-

MCS011_Q5

MCS011_Q5_Output

Leave a Reply