2D Array Help!

Confused I tried my best! :)

Page 1 of 1

3 Replies - 2682 Views - Last Post: 01 December 2009 - 06:19 PM Rate Topic: -----

#1 J.holloway718  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 20-October 09

2D Array Help!

Posted 01 December 2009 - 03:10 PM

:D

Write a c++ program that uses a two-dimensional array to store the highest and lowest temperature for six months a year.

Main
calls the 4 functions
Prompt user

Function 1
accepts and stores the lowest and highest temp

Function 2
calculates and returns the average low temp

Function 3
Calculates and returns the average high temp

Function 4
Output to the screen 2D array with the lowest and highest temp for each six months
the average low
and the average high

** Allow the user to continue using the program as a 'y' or 'Y' is a sentinel value to start and to continue using the program.
Format output and print in tabular format (static something)

Here is what I have so far, I am confused!! HELP!! :

#include <iostream>

using namespace std;

int acceptstore({}, {});
int calReturnlow();
int calReturnhigh();
int outputFunc();


int main()

{
int lowinput;
int highinput;
char cont;
cont = 'y';

cout<<"Enter Y or y to begin"<<endl;
cin>> cont;

while(cont=='Y' || cont== 'y')

{



cout<<"Please enter the lowest temperature for each month of six months"<<endl;
cin>> lowinput;

cout<<"Please enter the highest temperature for each month of six months"<<endl;
cin>> highinput;

acceptstore({], {});
calReturnlow();
calReturnhigh();
outputFunc();


return 0;

}

int accepts&store()
{

}

int calReturnlow()
{

}

int calReturnhigh()
{

}

int outputFunc()
{

}


*** MOD EDIT: Added code tags. Please :code: ***

This post has been edited by JackOfAllTrades: 01 December 2009 - 03:25 PM


Is This A Good Question/Topic? 0
  • +

Replies To: 2D Array Help!

#2 debjit625  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 51
  • View blog
  • Posts: 446
  • Joined: 06-September 08

Re: 2D Array Help!

Posted 01 December 2009 - 03:33 PM

You have to try more buddy. and for your 2d array
This is how we declare array
int myarray[10];


it means we have a array named "myarray" and it can store 10 integers
now we use it like this
myarray[0] = 100;//The first element contains 100
myarray[1] = 200;//The second element contains 200


Now comes 2d
This is how we declare 2d array
int my2darray[2][10];


what it says is we have 2 array of integers each contains 10 integers
and to use it
my2darray[0][0] = 100;//The first element of the first array contains 100
my2darray[1][0] = 200;//The first element of the second array contains 200


2d array are just like Matrix think them like that ,it will be easy to use them.
The array topic in C/C++ is very big you have to know more to use them
And what is this
acceptstore({], {});


i mean "{]" what is this.

Good luck
Was This Post Helpful? 0
  • +
  • -

#3 J.holloway718  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 20-October 09

Re: 2D Array Help!

Posted 01 December 2009 - 03:38 PM

Thanks Debjit!! This is what I changed so far. Am I on the right track. I have been programming for a couple months.

#include <iostream>

using namespace std;

int acceptstore(int max_temps[], int min_temps)
int calReturnlow();
int calReturnhigh();
int outputFunc();

int main()

{

char cont;
cont = 'y';

cout<<"Enter Y or y to begin"<<endl; 
cin>> cont;

while(cont=='Y' || cont== 'y')

{

cout<<"Please enter the lowest temperature for each month of six months"<<endl;
cin>> max_temps[];

cout<<"Please enter the highest temperature for each month of six months"<<endl;
cin>> min_temps[];
}

acceptstore(max_temps[], min_temps[]);
calReturnlow();
calReturnhigh();
outputFunc();


return 0;

}

int acceptsstore(max_temps[],min_temps[])
{

}

int calReturnlow()
{

}

int calReturnhigh()
{

}

int outputFunc(){}


Mod Edit: Added code tags: :code:
Was This Post Helpful? 0
  • +
  • -

#4 J.holloway718  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 20-October 09

Re: 2D Array Help!

Posted 01 December 2009 - 06:19 PM

Write a c++ program that uses a two-dimensional array to store the highest and lowest temperature for six months a year.

Main
calls the 4 functions
Prompt user

Function 1
accepts and stores the lowest and highest temp

Function 2
calculates and returns the average low temp

Function 3
Calculates and returns the average high temp

Function 4
Output to the screen 2D array with the lowest and highest temp for each six months
the average low
and the average high

** Allow the user to continue using the program as a 'y' or 'Y' is a sentinel value to start and to continue using the program.
Format output and print in tabular format (static something)

#include <iostream>

using namespace std;

int acceptstore(int max_temps[], int min_temps)
int calReturnlow();
int calReturnhigh();
int outputFunc();

int main()

{

int month_lowest_temp = 0; // used to keep track of the lowest temperature (for the low)
int month_highest_temp = 0; // used to keep track of the highest temperature (for the high)

int average_temperature = 0; // used to add up the averages for each month

char cont;
cont = 'y';

cout<<"Enter Y or y to begin"<<endl;
cin>> cont;

while(cont=='Y' || cont== 'y')

{

cout<<"Please enter the lowest temperature for each month of six months"<<endl;
cin>> max_temps[];

cout<<"Please enter the highest temperature for each month of six months"<<endl;
cin>> min_temps[];




cout << "The high temperature for the month is" << w.high << endl;
cout << "The low temperature for the month is" << w.low << endl;
cout << "The average temperature is " << w.average<<endl;
}

acceptstore(max_temps[], min_temps[]);
calReturnlow();
calReturnhigh();
outputFunc();


return 0;

}

int acceptsstore(max_temps[],min_temps[])
{

}

int calReturnlow()
{

//Monthly lows average
for ( int counter = 0; counter < YEAR; counter++)
{
lowestAvg += MonthlyData[counter].tempLow;
}
lowestAvg = (lowestAvg / YEAR);

}

int calReturnhigh()
{

//Monthly highs average
for ( int counter = 0; counter < YEAR; counter++)
{
highestAvg += MonthlyData[counter].tempHigh;
}
highestAvg = (highestAvg / YEAR);

//6 months average
for ( int counter = 0; counter < YEAR; counter++)
{
average += MonthlyData[counter].avgTemp;
}
average = (average / YEAR);

}

int outputFunc()
{


cout << "Average temperature of the year is: " << average_temperature / 6 << endl;
cout << fixed << showpoint << setprecision(2);




}


Mod Edit: added code tags: :code:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1