I need help finding the sum of the expense in this array. Please tell me whats wrong with this and help me fix it. Will appreciate it thank you
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
using namespace std;
int main()
{
char type[100];
double total=0;
double amount;
int numbers=0;
int i=0;
char name[30];
cout << "enter the employee name:"<< endl;
cin.getline(name,30);
cout << "enter the number of expense items:" << endl;
cin >> numbers;
cin.ignore();
while (i < numbers)
{
i++;
cout << "enter the type of expense:";
cin.getline(type,100);
cout << "enter the amount of expense:";
cin >> amount;
cin.ignore();
for (i=0; i <=numbers; i++)
{
total += amount[i];
i++;
cout << "total =" << total << endl;
}
}
}
|
Last edited on
One thing that is wrong is that the code is hard to read because you didn't use code tags [code] [/code]
Is amount
supposed to be an array? It is currently not an array but you try to use it as one on line 31.
it looks like it lol. I tried many things but didn't work and I forget to erase that lol.