I'm trying to combine 3 simple conversion programs I wrote into a larger one, with a menu over all of them. I suck at functions, and switches for that matter and I know I'm probably doing about 20 things incorrectly but I can't seem to figure it out. As you can guess, I'm a C++ newbie as well as a newbie to this board.
Errors:
warning C4508: 'main' : function should return a value; 'void' return type assumed
error C2143: syntax error : missing ';' before 'while'
error C2143: syntax error : missing ';' before '}'
error C2143: syntax error : missing ';' before '}'
error C2143: syntax error : missing ';' before '}'
error C2143: syntax error : missing ';' before '{'
error C2447: missing function header (old-style formal list?)
fatal error C1004: unexpected end of file found
Code:#include <iostream.h> #include <stdio.h> double weight (void); double height (void); double temperature (void); int main() { int result; /* restart variable */ int start; /* start variable */ switch (start){ case 1: weight(); break; case 2: height(); break; case 3: temperature(); break; default: printf ("Error, Please Enter 1,2,or 3:"); scanf ( "%i", &start); } printf( "\nEnter '1' to continue or '0' to quit.\n"); scanf( "%i", &result); } while (result != 0); } //////////////////////////////////////////////////////////////////////////////////////// /* Function Definitions */ double weight (){ int s1; /* local start variable */ double lb; /* weight in pounds */ double kg; /* weight in kilograms */ double f; /* answer */ puts( " 1) Pounds to Kilograms\n 2) Kilograms to Pounds\n "); scanf( "%i", &s1 ); if ( s1 == 1) { printf( " Enter the weight in pounds:"); scanf( "%lg", &lb); f = lb / 2.2 ; printf( " A weight of %lg pounds", lb); printf( " equals a weight of %lg kilograms", f); return f; } else if ( s1 == 2) { printf( " Enter the weight in kilograms:"); scanf( "%lg", &kg); f = kg * 2.2; printf( " A weight of %lg kilograms", kg); printf( " equals a weight of %lg pounds", f); return f; } else { printf( " Error."); } ////////////////////////////////////////////////////////////////////////////////// double height () { int s2; /* local start variable */ double ih; /* height in meters */ double eh; /* height in feet (fraction) */ double hf; /* answer */ puts( " 1) Pounds to Kilograms\n 2) Kilograms to Pounds\n "); scanf( "%i", &s2 ); if ( s2 == 1) { printf( " Enter the height in feet (as a fraction):"); scanf( "%lg", &eh); hf = eh * 3.25; printf( " A height of %lg feet", eh); printf( " equals a height of %lg meters", hf); return hf; } else if ( s1 == 2) { printf( " Enter the height in meters (as a fraction):"); scanf( "%lg", &ih); hf = eh / 3.25; printf( " A height of %lg meters", ih); printf( " equals a height of %lg feet", hf); return hf; } else { printf( " Error."); } //////////////////////////////////////////////////////////////////////////////// double temperature () { int s3; // local start variable double ft // temp fahrenheit double ct // temp celsius double r // result puts( " 1) Celsius to Fahrenheit\n 2) Fahrenheit to Celsius\n "); scanf( "%i", &s2 ); if ( s2 == 1) { printf( " Enter the temperature in Celsius:"); scanf( "%lg", &ct); r = (ct*1.8) + 32; printf( " A temperature of %lg Celsius", ct); printf( " equals a temperature of %lg Fahrenheit", r); return r; } else if ( s1 == 2) { printf( " Enter the temperature in Fahrenheit:"); scanf( "%lg", &ft); r = (ft-32)/ 1.8; printf( " A temperature of %lg Fahrenheit", ft); printf( " equals a temperature of %lg Celsius", r); return r; } else { printf( " Error."); }



LinkBack URL
About LinkBacks


