how can i make an array inside by a function?????

so that the value i will input will change....

I am using Borland C++.....

how can i start it????

  1. [SOLO] Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and lowest temperatures for the year. Your program must consist of the following functions:
    a. FunctiongetData:Thisfunctionreadsandstoresdatainthetwodimensionalarray.
    b. FunctionaverageHigh:Thisfunctioncalculatesandreturnstheaveragehightemperaturefortheyear.
    c. FunctionaverageHigh:Thisfunctioncalculatesandreturnstheaveragelowtemperaturefortheyear.
    d. FunctionindexHighTemp:Thisfunctionreturnstheindexofthehighesthightemperatureinthearray.
    e. FunctionindexLowTemp:thisfunctionreturnstheindexofthelowestlowtemperatureinthearray.(These functions must all have the appropriate parameters.)

i have made this program and i think its useles....

i am just a newbie....

#include<iostream.h>
#include<conio.h>
void getData();
void averageHigh();
int main()
{
clrscr();
getData();
getch();
return 0;
}



void getData()
{
int total;
int x,y,ht,lt;
const a=12,b=2;
int array[a][b];
{
    for(x=1;x<=12;x++)
 {
    cout<<"Month :"<<x<<endl;
    for(y=0;y<1;y++)
    {
      cout<<"Enter Highest Temperature: ";
      cin>>ht;
      }
        cout<<"Enter Lowest Temperature: ";
      cin>>lt;
 }
    }
        array[ht][lt];
            total=array[ht][lt];
    cout<<total;

}

sori for bad writting style.....

Dani AI

Generated

A concise, reliable structure for this assignment is to store month data in a 12×2 array (column 0 = high, column 1 = low) and implement the five functions the task asks for. Key points to avoid the mistakes in the original post: C/C++ arrays are zero‑based (months 0..11), you must pass the array and the number of rows to functions, and the second dimension must be known in the function parameter (or use std::vector for a dynamic structure). was right to call out missing initialization and brace/namespace issues; ’s note about posting formatted code is also helpful for debugging.

Example implementation (keeps the required function names and shows how to pass a 2D array to each function):

#include <iostream>
#include <iomanip>
#include <limits>

using namespace std;

const int MONTHS = 12;
const int FIELDS = 2; // 0 = high, 1 = low

void getData(int temps[][FIELDS], int months);
double averageHigh(const int temps[][FIELDS], int months);
double averageLow(const int temps[][FIELDS], int months);
int indexHighTemp(const int temps[][FIELDS], int months);
int indexLowTemp(const int temps[][FIELDS], int months);

// (Implementations follow the prototypes above — see full example in the post.)

Troubleshooting tips: validate input with a loop that clears bad input (see numeric_limits usage above), initialize any accumulators before use, and remember to report month numbers as index+1 when printing. If your Borland compiler requires old-style headers (e.g., <iostream.h>), adapt the includes but keep the same function structure. This approach gives clear separation of concerns: getData fills the array, the two averages compute averages, and the two index functions return month indices for the extremes — exactly what the assignment asks for.

Recommended Answers

All 5 Replies

There are many Mistakes in your Program.

Some of them i have found. But i will not post the total code for you i will only point the mistakes and you should solve them on your own.

So here Goes:

1)In your Program You are using functions like "cout<<" and "endl" but have not used the Namespace that holds all these functions .

I mean you need to add

using namespace std;

Into Your Code.

And After that.

Positioning of the Code Blocks. Just go to the code and try to analyse what you have programmed it to do.

Some things like Whether you have given the variables values before printing them out Should Be Checked.

Also The Usage of "{" and "}" Please check them too.

can you give me the overall format for the program???

just a summary..

i dont really know how to use array function...

i am using Borland C++

I prefer That you try to understand how the functions blocks are working and try to sort them out appropriately. And Try To Make Improvements.

Best of luck

commented: It was really necessary to hijack a 4 year old thread only to wish good luck to the person who posted, knowing that the thread is 4 years old. +0
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.