This is a question I asked myself when I was writing a school program.
I came up with a way around it, and now I have a larger problem. I am
looking for a program that could be compiled for any platform, so I am
using ANSI standard.
Could someone please look at the code(below) and tell me what is wrong?
Thanks in advance.
/************************************************/
/* (C) 28th May 1998 David
Illsley */
/* Higher Computing Project */
/* Version 2.3 */
/* A Program which converts: */
/* cm to inches (Distance) */
/* kg to pounds (Weight) */
/* C to F (Temperature) */
/* Litres to Gallons (Volume) */
/************************************************/
/*Sets the names of the standard librarys that we need to use*/
#include <stdio.h>
/*initialise all of the global variables*/
float toconvert = 1;
float converted = 1;
char againmenu = 0;
char mainmenu;
/*Function Definitions*/
void menu(void); /* Displays the Main Menu */
void choose(void); /* Processes Main Menu choice */
void again(void); /* Asks what to do next */
void cmin(void); /* Centimetres to Inches */
void incm(void); /* Inches to Centimetres */
void kgpounds(void); /* Kilograms to Pounds */
void poundskg(void); /* Pounds to Kilograms */
void centfar(void); /* Centigrade to Farenheight */
void farcent(void); /* Farenheight to Centigrade */
void litgal(void); /* Litres to Gallons */
void gallit(void); /* Gallons to Litres */
/* This Function is in all C Programs and calls all of the other
functions */
int main(void){
menu();
Quote:
}
void menu(void){
printf("\n\n Conversions"
"\n\n 1. Centimetres to Inches"
"\n\n 2. Inches to Centimetres"
"\n\n 3. Kilograms to Pounds"
"\n\n 4. Pounds to Kilograms"
"\n\n 5. Centigrade to Farenheight"
"\n\n 6. Farenheight to Centigrade"
"\n\n 7. Litres to Gallons"
"\n\n 8. Gallons to Litres"
"\n\n Please enter your choice: ");
scanf("%c", &mainmenu );
choose();
Quote:
}
void choose(void){
switch ( mainmenu )
{
case 49: cmin();
break;
case 50: incm();
break;
case 51: kgpounds();
break;
case 52: poundskg();
break;
case 53: centfar();
break;
case 54: farcent();
break;
case 55: litgal();
break;
case 56: gallit();
break;
default :{
printf("\nYou entered a wrong number. Please try again");
menu();
Quote:
}
}
}
void again(void){
printf("\n\nDo you wish to..."
"\n1. Do the same conversion again"
"\n2. Do a different comversion from the main menu"
"\n3. Exit the program\n"
"\nPlease enter your choice: ");
scanf("%c", &againmenu);
switch ( againmenu )
{
case 49:{
choose();
Quote:
}
break;
case 50:{
menu();
break;
Quote:
}
case 51:
break;
default:{
printf("You entered a wrong number. Please try again");
again();
Quote:
}
}
}
void cmin(void){
printf("Centimetres to Inches Conversion");
printf("\n\n Please enter the number of Centimetres: ");
scanf("%f", &toconvert );
converted = (toconvert * 0.4);
printf("\n\nThat is %f Inches.", converted );
again();
Quote:
}
void incm(void){
printf("Inches to Centimetres Conversion");
printf("\n\n Please enter the number of Inches: ");
scanf("%f", &toconvert );
converted = (toconvert * 2.5);
printf("\n\nThat is %f Centimetres.", converted );
again();
Quote:
}
void kgpounds(void){
printf("Kilograms to Pounds Conversion");
printf("\n\n Please enter the number of Kilograms: ");
scanf("%f", &toconvert );
converted = (toconvert * 2.2);
printf("\n\nThat is %f Pounds.", converted );
again();
Quote:
}
void poundskg(void){
printf("Pounds to Kilograms Conversion");
printf("\n\n Please enter the number of Pounds: ");
scanf("%f", &toconvert );
converted = (toconvert * 0.454);
printf("\n\nThat is %f Kilograms.", converted );
again();
Quote:
}
void centfar(void){
printf("Centigrade to Farenheight Conversion");
printf("\n\n Please enter the number of degrees Centigrade: ");
scanf("%f", &toconvert );
converted = ((9 * toconvert) + 160) / 5;
printf("\n\nThat is %f degrees Farenheight.", converted );
again();
Quote:
}
void farcent(void){
printf("Farenheight to Centigrade Conversion");
printf("\n\n Please enter the number of degrees Farenheight: ");
scanf("%f", &toconvert );
converted = ((toconvert - 32) * 5) / 9;
printf("\n\nThat is %f degrees Centigrade.", converted );
again();
Quote:
}
void litgal(void){
printf("Litres to Gallons Conversion");
printf("\n\n Please enter the number of Litres: ");
scanf("%f", &toconvert );
converted = (toconvert * 0.22);
printf("\n\nThat is %f Gallons.", converted );
again();
Quote:
}
void gallit(void){
printf("Gallons to Litres Conversion");
printf("\n\n Please enter the number of Gallons: ");
scanf("%f", &toconvert );
converted = (toconvert * 4.6);
printf("\n\nThat is %f Litres.", converted );
again();
Quote:
}
--
http://www.{*filter*}junkie.com/oxymoron
(Download my PGP Public Keyring from :
http://www.*-*-*.com/ ~gadget/pubring.pgp)
___________________________________________________
'If there were no Macintosh, it would be necessary to invent one.'
Michael E. Cohen