Thread: Need help with finding sum of an array plz.

  1. #1
    Registered User
    Join Date
    Nov 2011

    Need help with finding sum of an array plz.

    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
    #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;
            cout << "enter the number of expense items:" <<  endl;
            cin >> numbers;
            while (i < numbers)
            cout << "enter the type of expense:";
            cout << "enter the amount of expense:";
            cin >> amount;
            for (i=0; i <=numbers; i++)
                total += amount[i];
            cout << "total =" << total << endl;

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    New Zealand
    Please fix you indentation. A real programmer has perfectly formatted code - always.
    You may like to make things hard on yourself, but if you want others' help then you should make the code as tidily formatted as possible.

    The most obvious problem I see is that you're using the variable 'i' for both the inner and outer loop. You probably mean to have a separate variable for each loop.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Hannover, Germany
    Please tell me whats wrong with this
    Sorry, checking your code for syntax errors is your compilers job and it probably did it well. If you know the errors, post them and we will help you. I will not do the work a computer already did.

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Finding an array of unique values within a 2D array
    By saadashfaq in forum C Programming
    Replies: 6
    Last Post: 11-14-2011, 12:02 AM
  2. finding max in array using RECURSION
    By wonderwall in forum C Programming
    Replies: 5
    Last Post: 10-27-2011, 09:46 AM
  3. need help finding the max and min of a 2d array
    By finalreign in forum C Programming
    Replies: 6
    Last Post: 04-29-2009, 11:39 AM
  4. Finding the maximum in an array
    By Turtal in forum C Programming
    Replies: 4
    Last Post: 11-15-2006, 07:07 AM
  5. finding an int in an array
    By Geo-Fry in forum C++ Programming
    Replies: 3
    Last Post: 03-18-2003, 07:48 PM