hello
I have some errors in my program, which as always have to do with how to correctly syntax something :P ... I think :)
1st issue: I am using a 2d array as a parameter in a function but I am getting an error. I think it has to do with my syntax.
2nd Issue: When I use some float parameters within the 2d array I get an error
the 2nd error is:
invalid types `float*[float]' for array subscript
Function
void enterPurchase(float pur[], float nWeek, float counter) {
float purchase = 0;
while (!cin.fail() && cin>>purchase) { // while a correct input is input
cin >> purchase; // enter recent purchase
pur[nWeek][counter] = purchase; // 2nd Issue error occurs here counter++;
}
for (int i=0; i<counter; i++) {
cout << "Purchase No." << i+1 << ": $";
cout << pur[nWeek][i] << "\n"; // 2nd Issue error occurs here
}
}
whole program: with 1st issue
#include <cstdlib>
#include <iostream>
using namespace std;
float pur[53][25]; // Purchases Array [week number][purchase no.1, p2, pn...]
void printMenu();
void printBudget();
void getWeek(int& week);
void enterPurchase(float pur[], float nWeek, float counter);
int main()
{
char option;
int week = 0;
while (option!='3' && !cin.fail()) {
printMenu();
cin >> option;
switch (option) {
case '1':
getWeek(week);
enterPurchase(pur,week,0); // 1st issue error
//printBudget(week);
break;
case '2':
//printBudget();
break;
default:
cout << "Incorrect input \n";
break;
}
}
//system("PAUSE");
return EXIT_SUCCESS;
}
void printMenu() {
cout << "\tPersonal Budget " << endl << endl;
cout << " 1 : Add Purchase " << endl;
cout << " 2 : Print Budget Summary " << endl;
cout << " 3 : Quit " << endl << flush;
}
void printBudget() {
}
void getWeek(int& week) {
}
void enterPurchase(float pur[], float nWeek, float counter) {
float purchase = 0;
while (!cin.fail() && cin>>purchase) { // while a correct input is input
cin >> purchase; // enter recent purchase
pur[nWeek][counter] = purchase; // store recent purchase in relevent array element
counter++;
}
for (int i=0; i<counter; i++) {
cout << "Purchase No." << i+1 << ": $";
cout << pur[nWeek][i] << "\n";
}
}