I have this exercise that i need some help with !!

• Write the function fahrenheit that returns the Fahrenheit equivalent (as a float value) of a temperature value in Celsius. The function has one integer parameter for the temperature in Celsius.
[Hint: Tf = (9/5)*Tc+32; Tc = temperature in degrees Celsius, Tf = temperature in degrees Fahrenheit]
• Write another function printTempratures which receives two integer arguments low and high. The function uses the function fahrenheit to print all the Fahrenheit temperatures for all the Celsius temperatures in the range between low and high.
• Your main program tests the two functions by asking the user to enter a range and printing the Fahrenheit equivalence for all the Celsius values in that range.
• The following shows a sample run.

Enter the low Celsius value: 5
Enter the high Celsius value: 9

Celsius Fahrenheit
5 41.0
6 42.8
7 44.6
8 46.4
9 48.2

and i'll be so thankful :)

Dani AI

Generated

A compact, complete example is below. As observed, the conversion is a single arithmetic expression and the table is produced with a simple loop. asked for code, so the snippet implements the required functions and preserves the prompt name printTempratures (typo kept). reminded everyone to show effort when asking for help; the code here can be used as a working reference.

#include <iostream>
#include <iomanip>

float fahrenheit(int celsius) {
    return celsius * 9.0f / 5.0f + 32.0f;
}

void printTempratures(int low, int high) {
    if (low > high) { int t = low; low = high; high = t; }
    std::cout << "Celsius\tFahrenheit\n";
    std::cout << std::fixed << std::setprecision(1);
    for (int c = low; c <= high; ++c)
        std::cout << c << '\t' << fahrenheit(c) << '\n';
}

int main() {
    int low, high;
    std::cout << "Enter the low Celsius value: ";
    if (!(std::cin >> low)) return 0;
    std::cout << "Enter the high Celsius value: ";
    if (!(std::cin >> high)) return 0;
    printTempratures(low, high);
    return 0;
}

Notes and common pitfalls: make the division floating point (use 9.0f/5.0f or 9.0/5.0) to avoid integer truncation. Use std::fixed and std::setprecision(1) to match one decimal place. The example swaps low/high if entered in reverse; if the assignment forbids that, replace the swap with an input check and an error message. did not include an attempt, so posting any partial code next time will elicit faster, more targeted fixes.

Recommended Answers

All 3 Replies

So, what exactly do you need help with? I don't see any questions on your part nor do I see any code that you may need help with so I have no idea what you want from us.

Please read the following:
http://www.daniweb.com/forums/announcement8-2.html

...but we do want to help :) we just need to see that you've put in some effort.

This is...really not that hard...The first function is basically one line manipulating the variable with the calculation you were given. The second function is the exact same thing but in a loop from lower bound to higher bound.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.