PDA

View Full Version : C++ Help


nazma
07-23-2003, 10:24 PM
I am taking this C+ +programming class online and is really struggling learning the concept. Would someone be so kind to help me out with this problem:

A weather station will take 3 temperature readings each day for 7 days (Celsius) before reporting the aggregate data.
I would like to create a program that will read in the 21 Celsius temperature values and store the values in a two-dimensional array.
I would also like to create separate functions for the following tasks:
a. Calculate the average temperature
b. Calculate the high temperature
c. Calculate the low temperature
From the main function, I would like to call the functions created to retrieve the average, high, and low temperatures and display the results in both Fahrenheit and Celsius.
I would like to use the following formula to convert from Celsius to Fahrenheit:
Fahrenheit = Celsius * (212 – 32) / 100 + 32



Thanks

Nazma

Smerdyakov
07-23-2003, 11:43 PM
You need to ask a specific question if you want to be helped. (No, "how do I write this program?" doesn't count.) You won't find many people willing to write programs for you on the web.

DNAunion2000
07-24-2003, 10:40 PM
/*DNAunion*/ This won't compile...it's not meant to (as someone else pointed out, it's not really right to ask someone to write a whole program for you. Besides, you need to find and correct errors and work your way through the program yourself...that's how you'll learn) . But it should help you get going.


#include <iostream>

using std::cin;
using std::cout;
using std::endl;

const int DAYS = 7;
const int READINGS = 3;

// function prototypes
double calculateAvg(double temps[][READINGS]);
double calculateHigh(double temps[][READINGS]);
double calculateLow(double temps[][READINGS]);
double c2f(double degreesC);

int main()
{
double cTemps[DAYS][READINGS];

for (int day = 0; day < 7; ++day)
{
for (int reading = 0; reading < 3; ++reading)
{
// you could make this more meaningful
// by including the day and reading in
// prompt.
cout << “Enter Celsius temperature: “;
cin >> cTemps[day][reading];
}
}

cout << endl;
cout << “In degrees C:” << endl;
cout << “Avg temp is: “ << calculateAvg(cTemps) << endl;
cout << “Max temp is: “ << calculateHigh(cTemps) << endl;
cout << “Min temp is: “ << calculateMin(cTemps) << endl;

cout << endl;
cout << “In degrees F:” << endl;
cout << “Avg temp is: “ << c2f(calculateAvg(cTemps)) << endl;
cout << “Max temp is: “ << c2f(calculateHigh(cTemps)) << endl;
cout << “Min temp is: “ << c2f(calculateMin(cTemps)) << endl;

return 0;
}

// function definitions omitted

Smerdyakov
07-24-2003, 10:52 PM
I think this is already too much, to the point that you hurt the question asker's learning process by giving it to him and encouraging him to come here and ask again the next time he doesn't want to think about a problem.

coldflame
08-21-2003, 02:40 PM
I agree with you smerd.
don't ask for the code. Ask how to do the parts of the code you dont understand and figure the rest out on your own.

If someone writes it for you.
The next time you'll be ****ed.

gish
08-21-2003, 04:45 PM
Not really hurtful at all....for the folowing reasons:

the best way to teach is to show example, get the developer started. Next time he will have an example that he worked on, and can take this to the next problem given.

Smerdyakov
08-21-2003, 04:47 PM
If he is taking a class that does not direct him to such "getting you started" examples, then he should find a different class.

gish
08-21-2003, 05:12 PM
most examples I have seen during "my" getting started class, are so general that it was very difficult for new coders to see how to apply the example. Sometimes a real example is all that was needed.

coldflame
08-21-2003, 05:14 PM
I also think that examples are best for learning, but in this situation he just did the guys homework for him without really explaining what was in the code he gave.

Smerdyakov
08-21-2003, 07:21 PM
gish, what you said does not counteract the validity of my suggestion. "Real examples" are examples too, and if a class should have them but doesn't, the class shouldn't be used. It sounds like nazma has flexibility in choice of classes, so I don't think recommending taking another class would be unhelpful or irrelevant. (Of course, there's always the possibility that it really is a great class and he's too lazy to read through the provided material.)

gish
08-21-2003, 07:58 PM
Originally posted by coldflame
I also think that examples are best for learning, but in this situation he just did the guys homework for him without really explaining what was in the code he gave.
Did it for him?
Try to compile it.......--

edit: I take back original reply....to narrow it down, who cares?

coldflame
08-21-2003, 08:57 PM
I know, what a waist of time... who cares?