Skip to main content

UNIT CONVERTER PROGRAM IN C.

THIS PROGRAM IS WRITTEN IN C /* Program to convert length to different units*/ #include 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, Y, or M): "); scanf("%c", &inUnits); printf("Enter the unit to convert value to (c, m, or k): "); 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 'Y': converted = measure * 0.9144402; printf("The length you entered in yards is equal to %f meters", converted); break; case 'M': converted = measure * 1.60935; printf("The length you entered in miles is equal to %f kilometers", converted); break; case 'F': switch(outUnits){ case 'c': converted = measure * 30.4801; printf("The length you entered in feet is equal to %f centimeters", converted); break; case 'm': converted = measure * 0.304801; printf("The length you entered in feet is equal to %fmeters", converted); break; 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; } Faq

Comments

Popular posts from this blog

PROGRAMMING WITH C 7.12      (Card Shuffling and Dealing) Modify the program in Fig. 7.24 so that the card-dealing function deals a five-card poker hand. Then write the following additional functions: a) Determine whether the hand contains a pair. b) Determine whether the hand contains two pairs. c) Determine whether the hand contains three of a kind (e.g., three jacks). d) Determine whether the hand contains four of a kind (e.g., four aces). e) Determine whether the hand contains a flush (i.e., all five cards of the same suit). f) Determine whether the hand contains a straight (i.e., five cards of consecutive face values) ANSWER 7.12 #include<stdio.h> #include<stdlib.h> #include<time.h> //main functions void shuffle( int wDeck[][ 13 ] ); void deal( const int wDeck[][ 13 ], const char *wface[], const char *wSuit[], char *wfSuit[], char *wfFace[] ); //operation functions void pair( const char *wfSuit[], const cha
Hei guys ! Watch out for more on c plus plus
NEW RELEASE!!  C PLUS PLUS (C++ ) BY PROF SAM QUESTIONS AND ANSWERS Q1.   Date Design a class called Date that has integer data members to store month, day, and year. The class should have a three-parameter default constructor that allows the date to be set at the time a new Date object is created. If the user creates a Date object without passing any arguments, or if any of the values passed are invalid, the default values of 1, 1, 2001 (i.e., January 1, 2001) should be used. The class should have member functions to print the date in the following formats: 3/15/13 March 15, 2013 15 March 2013 Demonstrate the class by writing a program that uses it. Be sure your program only accepts reasonable values for month and day. The month should be between 1 and 12. The day should be between 1 and the number of days in the selected month. ANSWER. #include <iostream> #include <cstring> using namespace std; class Date {