Thread: First assignment help

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    2

    First assignment help

    This is my first C++ class and I stuck on the first assignment.
    this is the assignment:

    "The formula to convert Fahrenheit to Centigrade is: c = 5/9 * (f – 32)

    There is also an approximation of the conversion given by taking half the Fahrenheit temperature and subtracting 15. You want to do it both ways and determine how good of an approximation this is.

    Write a C++ program that prompts the user for a temperature in Fahrenheit, computes the centigrade equivalent using the actual formula, computes the approximation, and computes the percent difference between the two.

    Your program must check that the Fahrenheit temperature is in the range:
    -30 <= F <= 120
    If the Fahrenheit temperature is not within this range, print out an appropriate message and terminate the program.

    Input: Temperature in Fahrenheit

    Output:
    1. Temperature in Fahrenheit
    2. Actual temperature in centigrade using (c = 5/9 * (f – 32) )
    3. approximated temperature in centigrade
    4. percent difference between the approximation and the actual temperature."


    Can some please show exactly how I would type in that calculation?

    Thanks Leon

  2. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    Writing equations in C++ works pretty much the same way how you would write it out. If you're not sure on what the equations are, you should be looking elsewhere. If you're confused on something such as syntax, what specificly are you having troubles with?

  3. #3
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903

    :)

    That.. was exactly my first assigment in c++ as well
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You've got the calculation. Just declare your variables c and f, and fill them accordingly.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Lightbulb Equations, expressions, and assignment-statments

    In C++ (and every other programming language I know of) the equal sign is the assignment operator. It assigns the value on the right to the variable on the left. This means that everything on the right must be defined (known). And, the expression on the right must evaluate to a value.

    x = 3; //OK
    y = x + 3; //OK if x is defined
    c = (5.0/9.0 * (f – 32) ); / /OK if f is defined

    2 = x; //NO!
    x + 2 = 3; // NO!

    Note that you might have to put decimals in 5.0/9.0 so that the compiler stores the division-result as a float.

  6. #6
    Registered User
    Join Date
    Jun 2004
    Posts
    2
    Thanks guys, I got it now


    Leon

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    x + 2 = 3; // NO!
    That depends on what x is defined as. This could be legal.

    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    Registered User
    Join Date
    Jul 2004
    Posts
    8
    Quote Originally Posted by quzah
    That depends on what x is defined as. This could be legal.

    Quzah.
    Legal? As in it will compile or as in it's doing what he wants it to do? It should compile fine, unless x is undeclared then maybe some error will be given. Throw it in a conditional statement and it will work, but neither one of those is what he 'wants' to do.


    Wow, not only was this like my 3rd assignment in HS, my first one in college but I've helped like 5 irl people do this. Mainly just make sure that you have 5.0/9.0. That usually is the problem. If your taking a class, I would suggest remembering that well for the test

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 02:34 AM
  2. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 09:46 PM
  5. Replies: 1
    Last Post: 10-27-2006, 01:21 PM