Array sales bar chart
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Array sales bar chart

  1. #1
    Join Date
    Dec 2012
    Posts
    1

    Array sales bar chart

    Hello. I'm a new programmer and I need help or a hint with a homework assignment. I need to make a bar chart with asterisks that looks like this:


    Store 1: ******
    Store 2: ***

    etc.

    anyway, right now what I have is:

    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    int main ()
    {
        const int STORES = 5;
        int sales[STORES], i;
        
        for (i = 0; i < STORES; i++)
        {
            cout << "Please enter today's sales for store " << i + 1 << ": $";
            cin >> sales[i];
            sales[i] /= 100;
        }
        
        for(int i = 0; i < 10; i++)
        {
            cout << "*";
        
        cout << endl << endl;
        cout << "SALES BAR CHART" << endl;
        cout << "(Each * = $100)" << endl;
        cout << "Store 1: " << sales[0]  << endl;
        cout << "Store 2: " << sales[1] << endl;
        cout << "Store 3: " << sales[2] << endl;
        cout << "Store 4: " << sales[3] << endl;
        cout << "Store 5: " << sales[4] << endl;
        return 0;
       }
    }
    It's not displaying asterisks and I just need a little help. I'm a beginner and completely
    burnt out. I'm programming on xcode so it might look a little weird (?) works fine in visual studio though.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,121

    Re: Array sales bar chart

    Your second for loop is pretty wacky. You want an outer loop that goes from 0 to 1 less than STORES, and inside that, a loop that prints asterisks based on the number inside your sales array.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center