Thread: C++ Help

  1. #1
    nbepat
    Guest

    C++ Help

    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

    This is what I came up with:

    This won't compile. Is there someone that might have some
    time to help me out, I really appreciate it.

    #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

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    This won't compile. Is there someone that might have some
    How about telling us why it won't compile? (ie: Look at the reason why it won't compile. You compiler tells you this.) Post the first error message you get.

    Use code tags. A number of people, me included, don't even bother reading code that doesn't use them. You didn't bother reading the forum rules, why should we bother helping?

    Anyway, post the errors you're getting.

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

  3. #3
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    your passing to functions wrong... you can only pass one dimension of any array to a function... your trying to pass both dimensions...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    Use code tags

    Code:
    #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; 
    }

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    A couple of things,

    Code:
    cout << “Enter Celsius temperature: “;
    should be
    Code:
    cout << "Enter Celsius temperature: ";
    Look at this function call here
    Code:
    cout << “Min temp is: “ << calculateMin(cTemps) << endl;
    sure it's spelled correctly ? look at your prototypes..

    You also got too many '}' in your program. You should really try to format your code better, it's a lot easier to spot such errors then.

Popular pages Recent additions subscribe to a feed