Hello, it's me again, and I'm stuck again. I need to enter the highest and lowest temperatures for seven days, which the program will then store in two columns, with the average of each column stored in the bottom row. I got it working and everything, except that it'll only let me enter one set of numbers and doesn't display the average.

I know there's a thread with about this, but I couldn't fully understand it. I'm not really C++ literate, this is for a required class.

#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;



int main()
    {
    //declare array
    int temp[7][2]= {0};
    int day = 0;
    const int lowtemp = 0;
    const int hightemp = 1;

    //enter data into array
    cout<<endl<<"Enter Day: ";
    cin >> day;
    cout << "\nEnter low temperature: ";
    cin >> temp[day][lowtemp];
    cout << "\nEnter high temperature: ";
    cin >> temp[day][hightemp];

    //test
    cout << "\nDay: " << day << " High: " << temp[day][hightemp] << " Low: " << temp[day][lowtemp] <<endl;

    system("pause");
    return 0;
    } //end of main function

Recommended Answers

All 7 Replies

Your code is incomplete. All you do is read 1 high and 1 low value, then output them... there is no code for anything more. To input more than one value you will need a loop of some sort, and to calculate the average you will need another. Your code isn't working because it isn't done! I feel like maybe you copied the code from somewhere and thus don't understand it, try learning c++ so you can become c++ literate, then you will find that this problem is quite simple. (A good source for learning c++ is learncpp.com)

The last post on this problem did metion a loop, but, while I do have some idea on how the loop should look, I have no idea where in the code to put it.

Where in the code should I put the loop?

I don't need to know what loop to use yet, I just need to know where in the code the loop should go.

Does it go under //test or does it get a section of it's own?

I need this thing turned in by tonight, so could someone help me, please?

I haven't marked the question as solved yet, could you guys help me solve it by tell me where in my code my loop should go?

I don't need to know what loop to use, I already have an idea of how it should look, what I DON'T know is where in my code the loop should go. I need to turn this code in by 11:59 tonight, so I need to know where the loop should go before then.

Again I ask, where do I need to put the loop?

Guys, I'm serious, I need help with this. I need it done tonight, not tomorrow, TONIGHT, and I can't finish the code if I don't even know where to put the loop. Just tell me and I promise I won't bother you unless I run into another snag I can't figure my way out of.

You can Put loop before output parameters.

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.