I'm writing a program that needs to have several functions. Other than main, one of them is a function called get_inputs. In get_inputs, the program will get information from the user, and then return all 4 of the values recieved to main.
I know that pointers need to be used here, so here is what I think needs to be done, but I know that it wont work.
First of all, I need to properly call the function in main. I also need to find out if the way that I've implemented the pointers is correct. I'm not sure what I need to put inside the braces in the userInput array. I don't even know if the format is correct. I've done some research, but it is really confusing for me. Could I get some help with both of these?
NOTE: there are more functions in the program, but they dont apply to this.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* Rows represent the months of the year, Columns represent the hours in a typical day */
#define NROWS 11
#define NCOLS 23
#define TRUE 1
#define FALSE 0
#define INSTALLATION_COST 2000
float panelEfficiency = 0.18, inverterEfficiency = 0.90;
int main()
{
int houseEnergyREQ, numBatteries, numInverters;
int flag = TRUE;
float userInput[4], panelCost, inverterCost, batteryCost,
panelArea, batteryRating = 4.8, inverterRating = 5.0,
insolDayMin, maxHourPanelOutput, insolHourMax, totalCost;
float *ptr_to_userInput;
float insolation_Matrix[NROWS][NCOLS];
while(flag)
{
float get_inputs(float userInput[]);
/* Switch userInput array to meaningful terms */
userInput[0] = houseEnergyREQ;
userInput[1] = panelCost;
userInput[2] = inverterCost;
userInput[3] = batteryCost;
/* Equation to calculate panelArea */
panelArea = houseEnergyREQ/(insolDayMin*panelEfficiency*inverterEfficiency);
/* Equation to calculate maxHourPanelOutput */
maxHourPanelOutput = insolHourMax*panelArea*panelEfficiency;
/* Equation to calculate numbatteries */
numBatteries = ceil(houseEnergyREQ/(inverterEfficiency*batteryRating));
/* Equation to calculate numInverters */
numInverters = ceil(maxHourPanelOutput/(inverterEfficiency*inverterRating));
/* Equation to calculate total cost */
totalCost = panelArea*panelCost + numBatteries*batteryCost + numInverters*inverterCost
+ INSTALLATION_COST;
printf("The total cost of your Solar panel system is %.2f $. \n", totalCost);
/* Give user an option to quit program */
printf("Do you wish to continue? (y/n) \n");
if(getchar() == 'n')
{
flag = FALSE;
}
}
system("PAUSE");
}
/*---------------------------------------*/
/* Function to get inputs houseEnergyREQ, panelCost, inverterCost, batteryCost */
float get_inputs(float userInput[4], *ptr_to_userInput)
{
*ptr_to_userInput = &userInput[]
printf("This program will calculate the total cost of your solar panel system.");
printf("Enter the daily required amount of energy for your house, in kWh : \n");
scanf("%f", &userInput[0]);
printf("Enter the cost of solar panels (per m^2), power inverters and batteries: \n");
scanf("*f %f %f", &userInput[1], &userInput[2], &userInput[3]);
return *ptr_to_userInput;
}