From Scratch - Need Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 05l8kr
    New Member
    • Sep 2006
    • 35

    From Scratch - Need Help

    I'm suppose to write a program to convert a temperature from Fahrenheit to Celsius or from Celsius to Fahrenheit.

    * Ask the user which way they want to convert (use a menu 1 = Fahrenheit to Celsius; 2 = Celsius to Fahrenheit)
    * Then have the user enter the temperature.
    * Convert the temperature to the new temperature
    * Print out the original temperature and the temperature in the new measurement

    At least 3 functions – one to get from the user a number to convert, another to do the conversion and a third to print the result. More functions might be a good idea.

    Make sure that the output clearly states the original number with the dimension and the new temperature and dimension.

    Ex. 30 degrees Celsius is 86 degrees Fahrenheit

    Conversion Rules: C = (5(F – 32))/9 and F = (9(C)/5) + 32
  • sivadhas2006
    New Member
    • Nov 2006
    • 142

    #2
    Originally posted by karlracki
    I'm suppose to write a program to convert a temperature from Fahrenheit to Celsius or from Celsius to Fahrenheit.

    * Ask the user which way they want to convert (use a menu 1 = Fahrenheit to Celsius; 2 = Celsius to Fahrenheit)
    * Then have the user enter the temperature.
    * Convert the temperature to the new temperature
    * Print out the original temperature and the temperature in the new measurement

    At least 3 functions – one to get from the user a number to convert, another to do the conversion and a third to print the result. More functions might be a good idea.

    Make sure that the output clearly states the original number with the dimension and the new temperature and dimension.

    Ex. 30 degrees Celsius is 86 degrees Fahrenheit

    Conversion Rules: C = (5(F – 32))/9 and F = (9(C)/5) + 32
    Hi,

    First try it yourself.
    If you faced any problem, post your code and explain the problem.

    Regards,
    M.Sivadhas.

    Comment

    • teddarr
      New Member
      • Oct 2006
      • 143

      #3
      I can help. I just wrote the program. What code do you have so far?

      Comment

      • 05l8kr
        New Member
        • Sep 2006
        • 35

        #4
        Originally posted by teddarr
        I can help. I just wrote the program. What code do you have so far?
        The nothing code. LOL what do you got

        Comment

        • sicarie
          Recognized Expert Specialist
          • Nov 2006
          • 4677

          #5
          Originally posted by karlracki
          The nothing code. LOL what do you got
          In that case, the same nothing code.

          But if you try it (and post your code/questions/errors) I'll help you with it.

          Comment

          • teddarr
            New Member
            • Oct 2006
            • 143

            #6
            I'd love to help but you gotta meet me half way. I'm not going to post the code for nothing. I benefit from helping you by either explaining it to you or by debugging your code. "WE" can get the assignment done, but you gotta meet me half way.

            Comment

            • 05l8kr
              New Member
              • Sep 2006
              • 35

              #7
              Code:
              #include <stdio.h>
              
              double get_input()
              {
              	double fahrenheit;
              	printf("Enter the degrees in Fahrenheit:");
              	scanf_s(" %lf", &fahrenheit);  /* Get's the degrees in Fahrenheit temperature from the user using a scanf statement.**/
              	return fahrenheit;
              }
              
              double calculate(double fahrenheit)    
              {          	
              	return ((fahrenheit - 32) * (5.0 / 9.0)); /*Calculates the degrees Celsius from the degrees Fahrenheit*/      
              } 
              
              void output(double fahrenheit)
              {   
              	printf("Degrees in Celsius = %3.1f \n", calculate(fahrenheit));/** Print you results to the output */
              }
              
              int main()
              
              {
                double fahrenheit = 0;/* temperature in degrees Fahrenheit */
                fahrenheit=get_input(); /* invokes get_input */
                output(fahrenheit);    /* invokes output */
              
               return 0 ;
              
              }
              This is what I have so far
              error C2065: 'scanf_s' : undeclared identifier
              Error executing cl.exe.
              I need to have all this
              * Ask the user which way they want to convert (use a menu 1 = Fahrenheit to Celsius; 2 = Celsius to Fahrenheit)
              * Then have the user enter the temperature.
              * Convert the temperature to the new temperature
              * Print out the original temperature and the temperature in the new measurement

              You must use at least 3 functions – one to get from the user a number to convert, another to do the conversion and a third to print the result. More functions might be a good idea.

              Make sure that the output clearly states the original number with the dimension and the new temperature and dimension.

              Ex. 30 degrees Celsius is 86 degrees Fahrenheit

              Conversion Rules: C = (5(F – 32))/9 and F = (9(C)/5) + 32

              Comment

              • thefarmer
                New Member
                • Nov 2006
                • 55

                #8
                Code:
                #include <iostream.h>
                
                
                void showMenu(); 
                double getInput();
                double convertFtoC(double);
                double convertCtoF(double);
                double convertMtoInch(double);
                double convertInchtoM(double);
                
                
                int main(void)
                {
                   double input     = 0.0;      
                   double converted = 0.0;      
                   int choice       = -1;      
                   while (choice != 0)          
                   {
                      showMenu();               
                      cin >> choice;            
                      if (choice != 0)          
                      {
                         input     = getInput();
                
                         if (choice == 1)
                            converted = convertFtoC(input);
                         else if (choice == 2)
                            converted = convertCtoF(input);
                         else if (choice == 3)
                            converted = convertMtoInch(input);
                         else if (choice == 4)
                            converted = convertInchtoM(input);
                         else
                	cout << "\nInvalid input. Please try again ...";
                	cout << "\nYou converted: " << input << " to " << 
                	converted; 
                		} 
                	}
                
                 } 
                
                
                void showMenu()
                {
                	cout << "\n\nWelcome to the Unit Converter"\n; 
                 	cout << "\n\t 1 \t convert degrees F to degrees C"; ...        // more statements similar to this 
                	cout << "\n\t 4 \t convert Inch to Meter"; 
                	cout << "\n"; cout << "\n\t 0 \t to quit"\n; 
                	cout << "Your choice: "; 
                      } 
                
                	double getInput() 
                {
                 cout << "\nPlease enter number to be converted: "; 
                 double Temp; 
                 cin>> Temp;
                   return Temp;
                }
                
                double convertFtoC(double F)
                {
                   return 5.0 / 9.0 * (Temp - 32);
                }
                
                // declare all function and return values similar to
                above!!!


                Ok I hope it might be of help, of course I didn't finish the program, finish it for extra credit

                regards,
                thefarmer
                Last edited by zmbd; Oct 14 '18, 04:10 PM.

                Comment

                Working...