- Joined
- Apr 28, 2001
- Location
- Kingwood, TX
I am writing this program for class. This assignment is to familiarize me with arrays. I am using Dev-C++ IDE and when I try to compile/run the program I get a wierd error but cannot make out where the issue is. I think it is pointing to my #include <iostream.h> but I am not positive. Take a look if you will please:
#include <iostream.h>
#include <conio.h>
int functUnits(int);
int main()
{
const int maxnum = 5;
int units[maxnum], x;
const float price[maxnum] = {9.92, 6.32, 12.63, 5.95, 10.29};
float amount[maxnum], total;
total = 0;
for (x = 0; x < maxnum; x++)
{
units[x] = functUnits(x);
amount[x] = price[x] * units[x];
}
cout << "\n Price Units Amount";
cout << "\n ----- ----- ------";
for (x = 0; x < maxnum; x++)
cout << "\n " << price[x] << units[x] << amount[x];
for (x = 0; x < maxnum; x++)
total = total + amount[x];
cout << "\n -------";
cout << "\nTotal: " << total << endl;
cout << "\n\n\nPress any key to continue...";
getch();
return 0;
}
int functUnits(int num)
{
int units[num];
cout << "\nPlease enter the amount of units: ";
cin >> units[num];
return num;
}
Thanks for any input anyone can provide!
#include <iostream.h>
#include <conio.h>
int functUnits(int);
int main()
{
const int maxnum = 5;
int units[maxnum], x;
const float price[maxnum] = {9.92, 6.32, 12.63, 5.95, 10.29};
float amount[maxnum], total;
total = 0;
for (x = 0; x < maxnum; x++)
{
units[x] = functUnits(x);
amount[x] = price[x] * units[x];
}
cout << "\n Price Units Amount";
cout << "\n ----- ----- ------";
for (x = 0; x < maxnum; x++)
cout << "\n " << price[x] << units[x] << amount[x];
for (x = 0; x < maxnum; x++)
total = total + amount[x];
cout << "\n -------";
cout << "\nTotal: " << total << endl;
cout << "\n\n\nPress any key to continue...";
getch();
return 0;
}
int functUnits(int num)
{
int units[num];
cout << "\nPlease enter the amount of units: ";
cin >> units[num];
return num;
}
Thanks for any input anyone can provide!