Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem that require to calculate data sale for each month for all branches so I need to make an unknown no. Of loops depending the no. Of branches user will enter

What I have tried:

I have tried loop but it will not be good because I dont know how many branches .then I tried nested loop the big loop for branches from 1 to n the inner loop for sales data[] from 0 to 11 as we have 12 months
Posted
Updated 6-Apr-20 9:54am

Try something like this:
C++
while (1 == 1)
   {
   // get record from user
   if (no record entered)
      {
      break;
      }
   }
 
Share this answer
 
Ask the user how many month he will enter. Than you have the end count for the loop. Else the while loop is the best idea.

Think about a valid exit condition and how to test.
 
Share this answer
 
Sounds like a simple database solution. Given that the app enters data into SQL compatible DB, the following statement should do the trick without the need of loops of any kind:

SQL
SELECT SUM(sales_column_name) FROM table_name


with the table looking something similar to

SQL
branch_name | sales_column_name
--------------------------------
branch 1    | 5000
branch 2    | 3000

Etc. 
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900