Skip to main content
0 online
theremin thereminOG 2002

Ok. That's done with. Here's 2 others I need help with that I'm posting in the midst of trying to figure it out in the meantime.

#1
an array called "alpha" with 50 components - type is double

initialise array so that the 1st 25 components are equal to the square of the index variable and the last 25 are equal to 3 times the index variable. output the array so 10 elements per line are printed.

#2
use a 2-D array to store the highest & lowest temperatures for each month of the year. Output the average high, avg. low, as well as the highest & lowest temps of the year.

It consists of 5 functions:

getData - reads & stores data in the 2D array

averageHigh - Calculates & returns the average high temps of the year obviously

averageLow - self-explanatory

indexHighTemp - returns the index of the highest high temperature in the array

indexLowTemp - just the opposite of the indexHighTemp function of course

If you can offer any help, thanks.

iwz iwz

what are you having trouble with on #1?

theremin thereminOG 2002

The biggest thing I need help with on is how to print out 10 elements per line

yay yayOG 2004

its just an array with 50 elements printed out in 10's

theremin thereminOG 2002

10 elements per line need to be outputted. But, How do I do that?

I thought maybe a nested for loop like this one

for (index = 0; index < 50; index++)
for (item = 0; item < 10; item++)
cout << alpha[index] << " " << endl;

But, is that how?

Probably nothing like that, right?

I doubt myself.

yay yayOG 2004

There ya go. But the first loop should not be increased by 1, but 10, otherwise you'll have 40 more sets of 10 printing out then expected

D
dgiaimoOG 2003

Not quite. What you want is more like:

for (i = 0; i < 5; i++)
{

for (j = 0; j < 10; j++)
{
cout << alpha[10*i + j] << " ";
}

cout << endl;
}

theremin thereminOG 2002

Here's what I did (Doesn't work properly tho)

#include
#include

using namespace std;

int main(int argc, char *argv[])
{

double alpha[50];
int index;

for (index = 0; index < 25; index++)

alpha[index] = index^2;

if (index == 10)
cout << alpha[index] << endl;
else if
(index == 20)
cout << alpha[index] << endl;
else cout << alpha[index] << " ";



for(index = 25; index < 50; index++)
alpha[index] = index * 3;

if (index == 30)
cout << alpha[index] << endl;
else if
(index == 40)
cout << alpha[index] << endl;
else if
(index == 50)
cout << alpha[index] << endl;
else cout << alpha[index] << " ";




system("PAUSE");
return EXIT_SUCCESS;
}

yay yayOG 2004

First of all ^ does not do what you think it does, its an exclusive or logical operator, not power, you want to include cmath and use pow for that.

Second, I'd be amazed if you could even tell me in english what that code does. Any good compiler would complain that index at lines x y and z will never be 10, 20, 30, 40, or 50, a clue right there that your printing is notpart of your looping calculation.

First, do your calculations which looks like you want to square the index and store it into the first 25 elements, then multiples of 3 on the index for the remaining 25 (two seperate loops)

THEN, do your print out code, which we already gave you tips on in other comments

D
dgiaimoOG 2003

Maybe if you told us what you were having trouble on we could be more useful. I could easily do the problems for you, but I fail to see how that would help you.

yay yayOG 2004

lol yeah i know, do you want us to do it for you, or learn how to do it?

theremin thereminOG 2002

Do it for me

Welcome Back to eZabel

It's been a while. Here's what's new.

eZabel Lore

A complete history of our community — stats, Hall of Fame, legendary threads, and more.

View the Lore →

Everything Preserved

All 225,969 pieces of content from 2000–2014 are here — forums, messages, journals, photos, polls, and events.

💎

Gems

Spot something you love — a legendary comment, a classic thread, a great photo? Log in and click the diamond icon to mark it as a Gem. Add a note about why it's special. The best stuff surfaces on the Gems page.