Thread: some help needed.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    That marked section is a problem. What if the salesperson has $0 in sales (the lowest possible). Then the totalearnings will be $200. That divided by 100 is 2, so you are incrementing the counter at index 2. What happened to indexes 0 and 1? You need to take that index calculation and account for the fact that $200-$299 should be at index 0, and with the rest following after it.

  2. #2
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    Code:
    using std::cout;
    using std::endl;
    using std::cin;
    using std::getline;
    Why don't you use
    Code:
    using namespace std;
    ???

    Also, in your code, the array's index will start at the index "2" because you always add it with 200. And because the index is started at "2", the supposed index of 7 & 8 won't be processed.

    Just remove the 200 in:
    Code:
    totalearnings[x] = ( (procentless[x]*0.09) + 200 );
    ERROR: Brain not found. Please insert a new brain!

    “Do nothing which is of no use.” - Miyamoto Musashi.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by g4j31a5
    Why don't you use
    Code:
    using namespace std;
    ???
    Maybe because it is not a good practice?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    Quote Originally Posted by vart
    Maybe because it is not a good practice?
    So does
    Code:
    using std::cout;
    using std::endl;
    using std::cin;
    using std::getline;
    ERROR: Brain not found. Please insert a new brain!

    “Do nothing which is of no use.” - Miyamoto Musashi.

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    86
    Quote Originally Posted by g4j31a5
    Code:
    using std::cout;
    using std::endl;
    using std::cin;
    using std::getline;
    Why don't you use
    Code:
    using namespace std;
    ???

    Also, in your code, the array's index will start at the index "2" because you always add it with 200. And because the index is started at "2", the supposed index of 7 & 8 won't be processed.

    Just remove the 200 in:
    Code:
    totalearnings[x] = ( (procentless[x]*0.09) + 200 );

    ehm sorry to say but, this does not solve the problem, im not even going to try that cause that line is just to CALCULATE the totalearnings and has nothing to do with the array frequency, and thats where the fault is ...

    just for a quicky , this stands for : "The salespeople each receive $200 per week plus 9 percent" as noted in the assignment.

    but thanks for trying tough,

  6. #6
    Registered User
    Join Date
    Nov 2006
    Posts
    86
    i give up , i think there is no possible solution for me with the knowledge i should have from that chapter+all the ones before it. (which isnt alot) also i think that the question is not clear enough ... well it is but i need some tips

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Quote Originally Posted by Daved
    That marked section is a problem. What if the salesperson has $0 in sales (the lowest possible). Then the totalearnings will be $200. That divided by 100 is 2, so you are incrementing the counter at index 2. What happened to indexes 0 and 1? You need to take that index calculation and account for the fact that $200-$299 should be at index 0, and with the rest following after it.
    That still doesn't explain why the totals printed add up to 16, not 20.

    [edit] Wait.

    Code:
      for (int x = 0; x < employees ; x++)
      {
        totalearnings[x] = ( (procentless[x]*0.09) + 200 );
        if ( (totalearnings[x]   ) > 1000)
        {
          frequency[8]++;
        }
        else
        {
          frequency[ (totalearnings[x] / 100 ) ]++;  // problem:  cast to int makes some 
          // values turn to 0
        }
        cout << endl;
      }
    What if totalearnings[x] is 900? There's your problem. You're right, Daved. Sorry. [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Registered User
    Join Date
    Nov 2006
    Posts
    86
    yes ehm sorry david , i kande missed your post, but i was replying to the guy i quoted :P

    ok this is what im trying now :

    Code:
    void earningslog::Setearnings (float procentless[])
    {
      const int frequencysize = 9;
      int frequency[frequencysize] = {0};
    
    
      for (int x = 0; x < employees ; x++)
      {
        float sub = procentless[x]*0.09;
        totalearnings[x] = ( sub + 200 );
        if ( (totalearnings[x]   ) > 1000)
        {
          frequency[8]++;
        }
        else
        {
          const float test = 0.50;
          float   sub  = totalearnings[x]/100;
          cout << sub <<"\t"<< (int)sub << endl;
    
          frequency[(int)sub]++;
    
        }
    
    
    
    
        }
    
    
    
      outputbar (frequency);
    
    
    }
    
    void earningslog::outputbar   (int frequency [])
    {
    
      int x = 0;
      int y = 200;
    
      cout <<y <<"-"<<y+99 <<": " << frequency[x] << endl;
      x++,y+= 100;
      cout <<y <<"-"<<y+99 <<": " << frequency[x] << endl;
      x++,y+=100;
      cout <<y <<"-"<<y+99 <<": " << frequency[x] << endl;
      x++,y+=100;
      cout <<y <<"-"<<y+99 <<": " << frequency[x] << endl;
      x++,y+=100;
      cout <<y <<"-"<<y+99 <<": " << frequency[x] << endl;
      x++,y+=100;
      cout <<y <<"-"<<y+99 <<": " << frequency[x] << endl;
      x++,y+=100;
      cout <<y <<"-"<<y+99 <<": " << frequency[x] << endl;
      x++,y+=100;
      cout <<y <<"-"<<y+99 <<": " << frequency[x] << endl;
      x++,y+=100;
      cout <<"1000 and over:"<< frequency[x] << endl;
    
    
    }
    output:

    Code:
    E:\PROJECTMAP\test\tests\windows\Debug_Build\tests.exe
    2.9	2
    3.35	3
    3.8	3
    4.25	4
    4.7	4
    5.15	5
    5.6	5
    5.6	5
    6.5	6
    6.95	6
    8.3	8
    9.2	9
    4.7	4
    7.4	7
    9.9992	9
    8.9993	8
    7.9994	7
    6.9995	6
    5.9996	5
    200-299: 0
    300-399: 0
    400-499: 1
    500-599: 2
    600-699: 3
    700-799: 4
    800-899: 3
    900-999: 2
    1000 and over:3

    im sorry but i got to go to bed now i tought that i might use const float test = 0.50 and compare the sub numbers if their digets after the . are higher than zero, but well ...

    i made a loop in it printing sub and the integer cast to it

    ill look further tomorrow got to sleep now
    tnx guys



    ( i changed totalearnings to the type as float)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. free needed or not?
    By quantt in forum Linux Programming
    Replies: 3
    Last Post: 06-25-2009, 09:32 AM
  2. C Programmers needed for Direct Hire positions
    By canefan in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 09-24-2008, 11:55 AM
  3. lock needed in this scenario?
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-25-2008, 07:22 AM
  4. C++ help needed
    By Enkindu in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 08-31-2004, 11:24 PM
  5. semi-colon - where is it needed
    By kes103 in forum C++ Programming
    Replies: 8
    Last Post: 09-12-2003, 05:24 PM