Hello!
This is my first time attempting to get help but, alas, I'm desperate! I have been working on this program for a class (and it's due at midnight). I can't seem to grasp moving data in and out of arrays using nested for loops.

it's a matter of entering product defects (up to 10 products) over up to 10 days.
I have to be able to return:

total defects product/ total defects per day/ product with max defects/ product with min defects

I **almost** grasp the concept, but not well enough apparently :(

should I include my entire program (150+ lines) or just a portion of it?

Any assistance would be greatly appreciated!

Christina
(Mom of many)

Recommended Answers

All 14 Replies

Post the relevant portion first and then we can see if we need more information.

Thank you!

void enterData (int & numProd, int & trackDays, 
                int & numDef, int dayDefect[], int & d, int ttlDef,
                int SIZE, int totalDefect[], int maxDefect [], int i)
{
   //enter number of products
   cout << "\n\nEnter number of products: ";
   cin >> numProd;

   while (numProd <2 || numProd > 10)
   {
      cout << "The number of products must be between 2 and 10.\n\n";
      cout << "\n\nRe-enter number of products: ";
      cin >> numProd;
   }

   // enter days to track
   cout << "\n\nEnter number of days to track:  ";
   cin >> trackDays;

   while (trackDays < 2 || trackDays > 7) // error check days to track
   {
      cout << "\n\nThe number of days tracked must be between 2 and 7.";
      cout << "\n\n Re-enter number of days to be tracked: ";
      cin >> trackDays;
   }

   // enter defects per day into dayDefect array
   cout << "\n\nEnter defects for each day. Hit <enter> after each day's entry. ";
   cout << "\n\nDefects must be entered in integer form and separated by a space.";


   for (int d=0; d<=trackDays; d++)
   {
      cout << "\n\nDay " << d<< ": "; 
      for (int p  =1 ; p <= numProd; p++)
      {
         cin >>  dayDefect [p];              //calc & update totalDefect[]
         totalDefect [p] += dayDefect [p]; 

the menu works, I can enter data, but the prob is manipulating it!. After entering the defects per day, I want to be able to update totalDefect[]. from the output, it's not working.
thank you again!

Please use the [code] //code here [/code] tags, that way all of the formatting is preserved.

Why are you using p as your index for totalDefect? You probably meant d.

Also, how do you know the array you are passing in will have trackDays spots? If it has less than that your program will crash.

Relatedly, when you have a for loop going from 0 to trackDays (inclusive), you're going to have trackDays+1 elements.

Thank you! Where may I find info on the tags thing? I realizer formatting is important.

I had used p only because I thought it would conflict with the d in the days loop.
thank you so much for your really fast response. Sadly, I have to get to work, but I'll work on it this pm.

May I contimue on this thread if I have further difficulties?

Just type [code] at the beginning of your code and [/code] at the end :)

Yes, post back on this thread with any problems related to this assignment, start a new thread if it's pertaining to something else.

Ok. thx again. Phrenology, huh? :) Quantitative is the way to go. I've found that generally, quantity is often more readily available than quality. Have a good night. C

I'm back! I played with my program all last night and it's getting better. I have 3 erros: subscript requires array or pointer type (x3).

it's associated with the minDefect[p] array (lines 157 - 169). I only got this after I added the minDefect[] calculation. It's identical to the maxDefect calculation (I copied/pasted) which had no prob.

There are a couple of other issues, but I figure, one thing at a time!
Thx much in advance!

#include <cmath>
#include <iostream>
using namespace std;

// Function Prototypes
void displayMenu ();

void enterData (int & numProd, int & trackDays,
                int & numDef, int dayDefect[], int & d, int & ttlDef, 
                int totalDefect[], int maxDefect [], int minDefect []);

void calcTotalDefects( int dayDefect[],  int & ttlDef,
                      int SIZE, int  p, int & d, int & trackDays);

void totalProductDefects (int dayDefect[], int totalDefect[],
                          int i, int SIZE, int numProd, int p, int trackDays);

void maxDefects ( int maxDefect []);

void minDefects (int minDefect []);


int main ()
{
   //declare variables

   int ttlDefProd;   // total number of defects, and total defects per product
   int minDef, maxDef;    // minimum, and maximum defects
   int minVarProd;     //  Product with minimum variance
   int choice;              //Menu selection
   int numProd, trackDays, numDef; //number of products, days to track & defects
   int p = 0;    // product
   int d = 0;   // Day
   int ttlDef = 0;
   int i =0;     // defect
   int maxIndex = 0;

   // Arrays..............
   const int SIZE = 10;
   int dayDefect [SIZE] = {0};
   int totalDefect [SIZE] = {0};
   int minDefect [SIZE] = {0};
   int maxDefect [SIZE] = {0};

   do    // Runs overall program, regulating menu acccess,
   {       // processing functions, & program exit

      displayMenu ();      //Display options menu function
      cin >> choice;                   //Enter menu choice  
      while (choice < 1 || choice > 7)    //  validate choice............invalid entry
      {
         cout << "\n\n\nInvalid entry.  Please choose from options 1-7.  ";
         cin >> choice;
      }

      if (choice > 0 && choice < 8)   //............valid choice entry
      {
         //********Menu Switch**********************
         switch (choice)                                                      //   choice switch runs the menu.
         {                                                                                //    Each case will call the appropriate
         case 1:   // Enter data                                processing function
            enterData (numProd, trackDays, numDef, dayDefect, d,
               ttlDef, totalDefect, maxDefect, minDefect);      
            break;

         case 2:  // Total Defects                                 
            calcTotalDefects( dayDefect,  ttlDef, SIZE, p, d, trackDays);                                                           
            break;                                                                                  

         case 3:   // Total defects per product               
            totalProductDefects (dayDefect, totalDefect, i, SIZE, numProd, p, trackDays);
            break;

         case 4:   // Maximum defects
            maxDefects ( maxDefect);          
            break;

         case 5:  // Minimum defect
            minDefects ( minDefect);
            break;
         case 6:   // Product w/ min variance
            cout << "\n\nProduct with minimum vaiance: ";
            break;
         case 7:   // Program exit     
            cout << "\n\n\nExiting program. . . ";           
            break;
            // Error check
         }
      }
   }
   while (choice > 0 && choice < 7);



   //**********************************
   return (0);
}

//}

//*******************FUNCTIONS********************************
// Menu Function
void displayMenu ()
{
   cout << "   \n\n\n\n";
   cout << "*                              Main Menu                               *\n";
   cout << "                *****************************************\n\n";
   cout << "                 1. Enter Data\n";
   cout << "                 2. Report: Total number of defects\n";
   cout << "                 3. Report: Total defects per product.\n";
   cout << "                 4. Report: Maximum defects.\n";
   cout << "                 5. Report: Minimum defects.\n";
   cout << "                 6. Report: Product with minimum variance.\n";
   cout << "                 7. Exit\n\n\n";
   cout << "                  Choice:  ";

}


// enterData function
void enterData (int & numProd, int & trackDays, int & numDef, int dayDefect[],
                int & d, int & ttlDef, int totalDefect[], int maxDefect [], int minDefect)
{
   //enter number of products
   cout << "\n\nEnter number of products: ";
   cin >> numProd;

   while (numProd <2 || numProd > 10)
   {
      cout << "The number of products must be between 2 and 10.\n\n";
      cout << "\n\nRe-enter number of products: ";
      cin >> numProd;
   }

   // enter days to track
   cout << "\n\nEnter number of days to track:  ";
   cin >> trackDays;

   while (trackDays < 2 || trackDays > 7) // error check days to track
   {
      cout << "\n\nThe number of days tracked must be between 2 and 7.";
      cout << "\n\n Re-enter number of days to be tracked: ";
      cin >> trackDays;
   }

   // enter defects per day into dayDefect array
   cout << "\n\nEnter defects for each day. Hit <enter> after each day's entry. ";
   cout << "\n\nDefects must be entered in integer form and separated by a space.";


   for (int d=1; d<=trackDays; d++)
   {
      cout << "\n\nDay " << d<< ": "; 
      for (int p  = 1; p <= numProd; p++)
      {
         cin >>  dayDefect [p];
         minDefect [p]  =  dayDefect [p];
         ttlDef += dayDefect [p];       //calc total defects

         totalDefect [p] += dayDefect [p];  //calc & update totalDefect[]- (per product)

         if (dayDefect [ p] > maxDefect [p] ) // calc & update maxDefect[]
         {
            maxDefect [p] = dayDefect [p]; 
         }         

         if (dayDefect [p] < minDefect [p] ) //  calc & update minDefect []
         {
            minDefect [p] = dayDefect [p];
         }
      }
   }
}


void calcTotalDefects( int dayDefect[],  int & ttlDef, int SIZE, int  p, int & d, int & trackDays)
{
   cout << "\n\n\n\nTotal number of defects: " << ttlDef;   
}


void totalProductDefects (int dayDefect[], int totalDefect[], int i, int SIZE, int numProd, int p, int trackDays)
{   
   cout << "\n\nTotal defects over " << trackDays << " days for:\n\n";
   for ( int d = 1; d <= numProd; d++)    
   {
      cout << "\n\nProduct: " <<  d  << ": ";
   }
   for (int i = 0; i > SIZE; i++)
   {
      totalDefect [i] += dayDefect[i];
      cout << totalDefect[i] << endl;
   }
}


void maxDefects ( int maxDefect [])
{
   int i = 0;
   cout << "\n\nEnter product number: " ;
   cin >> i;
   cout << "\n\nThe maximum number of defects for Product ";
   cout << i << " is: " << maxDefect[i];
}

void minDefects (int minDefect [])
{
   int i = 0;
   cout << "\n\nEnter product number: " ;
   cin >> i;
   cout << "\n\nThe minimum number of defects for Product ";
   cout << i << " is: " << minDefect[i];
}

ADDENDUM!!!! I did it! The problemm has been solved (can't honestly say I remember how :))

The last problem I have is that when I calc min defects (line 176) my output is 0.

I get why, but I'm not sure how to fix it. If I say if dayDefect[] (user input) is less than minDefect[], since minDefect[] is initialized to 0, dayDefect[] will NEVER be less. The reverse works the same way. I need to set minDefect[] = to the first iteration of dayDefect[]. Any ideas?


Thank you thank you in advance!

Here is the most current version of my code:

#include <cmath>
#include <iostream>
using namespace std;

// Function Prototypes
void displayMenu ();

void enterData (int & numProd, int & trackDays,
                int & numDef, int dayDefect[], int & d, int & ttlDef, 
                int totalDefect[], int maxDefect [], int minDefect [], int  & minVar, int  & minVarProd);

void calcTotalDefects( int dayDefect[],  int & ttlDef,
                      int SIZE, int  p, int & d, int & trackDays);

void totalProductDefects (int dayDefect[], int totalDefect[],
                          int i, int SIZE, int numProd, int p, int trackDays);

void maxDefects ( int maxDefect []);

void minDefects (int minDefect []);

void minVariance (int maxDefect [], int minDefect [], int minVarProd, int minVar);



int main ()
{
   //declare variables

   int ttlDefProd;   // total number of defects, and total defects per product
   int minDef, maxDef;    // minimum, and maximum defects
   int minVarProd;     //  Product with minimum variance
   int choice;              //Menu selection
   int numProd, trackDays, numDef; //number of products, days to track & defects
   int p = 0;    // product
   int d = 0;   // Day
   int ttlDef = 0;
   int i =0;     // defect
   int maxIndex = 0;  
   int minVar;            // minimum variance (valu)


   // Arrays..............
   const int SIZE = 10;
   int dayDefect [SIZE] = {0};
   int totalDefect [SIZE] = {0};
   int minDefect [SIZE] = {0};
   int maxDefect [SIZE] = {0};

   do    // Runs overall program, regulating menu acccess,
   {       // processing functions, & program exit

      displayMenu ();      //Display options menu function
      cin >> choice;                   //Enter menu choice  
      while (choice < 1 || choice > 7)    //  validate choice............invalid entry
      {
         cout << "\n\n\nInvalid entry.  Please choose from options 1-7.  ";
         cin >> choice;
      }

      if (choice > 0 && choice < 8)   //............valid choice entry
      {
         //********Menu Switch**********************
         switch (choice)                                                      //   choice switch runs the menu.
         {                                                                                //    Each case will call the appropriate
         case 1:   // Enter data                                processing function
            enterData (numProd, trackDays, numDef, dayDefect, d, ttlDef, 
               totalDefect, maxDefect , minDefect, minVar, minVarProd);
            break;

         case 2:  // Total Defects                                 
            calcTotalDefects( dayDefect,  ttlDef, SIZE, p, d, trackDays);                                                           
            break;                                                                                  

         case 3:   // Total defects per product               
            totalProductDefects (dayDefect, totalDefect, i, SIZE, numProd, p, trackDays);
            break;

         case 4:   // Maximum defects
            maxDefects ( maxDefect);          
            break;

         case 5:  // Minimum defect
            minDefects ( minDefect);
            break;

         case 6:   // Product w/ min variance
            minVariance (maxDefect, minDefect, minVarProd, minVar);

            break;

         case 7:   // Program exit     
            cout << "\n\n\nExiting program. . . ";           
            break;
            // Error check
         }
      }
   }
   while (choice > 0 && choice < 7);



   //**********************************
   return (0);
}

//}

//*******************FUNCTIONS********************************
// Menu Function
void displayMenu ()
{
   cout << "   \n\n\n\n";
   cout << "*                              Main Menu                               *\n";
   cout << "                *****************************************\n\n";
   cout << "                 1. Enter Data\n";
   cout << "                 2. Report: Total number of defects\n";
   cout << "                 3. Report: Total defects per product.\n";
   cout << "                 4. Report: Maximum defects.\n";
   cout << "                 5. Report: Minimum defects.\n";
   cout << "                 6. Report: Product with minimum variance.\n";
   cout << "                 7. Exit\n\n\n";
   cout << "                  Choice:  ";

}


// enterData function
void enterData (int & numProd, int & trackDays,
                int & numDef, int dayDefect[], int & d, int & ttlDef, 
                int totalDefect[], int maxDefect [], int minDefect [], int & minVar, int & minVarProd)       
{
   //enter number of products
   cout << "\n\nEnter number of products: ";
   cin >> numProd;

   while (numProd <2 || numProd > 10)
   {
      cout << "The number of products must be between 2 and 10.\n\n";
      cout << "\n\nRe-enter number of products: ";
      cin >> numProd;
   }

   // enter days to track
   cout << "\n\nEnter number of days to track:  ";
   cin >> trackDays;

   while (trackDays < 2 || trackDays > 7) // error check days to track
   {
      cout << "\n\nThe number of days tracked must be between 2 and 7.";
      cout << "\n\n Re-enter number of days to be tracked: ";
      cin >> trackDays;
   }

   // enter defects per day into dayDefect array
   cout << "\n\nEnter defects for each day. Hit <enter> after each day's entry. ";
   cout << "\n\nDefects must be entered in integer form and separated by a space.";


   for (int d=1; d<=trackDays; d++)
   {
      cout << "\n\nDay " << d<< ": "; 
      for (int p  = 1; p <= numProd; p++)
      {
         cin >>  dayDefect [p];
         
         ttlDef += dayDefect [p];       //calc total defects

         totalDefect [p] += dayDefect [p];  //calc & update totalDefect[]- (per product)

         if (dayDefect [ p] > maxDefect [p] ) // calc & update maxDefect[]
         {
            maxDefect [p] = dayDefect [p]; 
         }      

         if (dayDefect [p] < minDefect [p] ) //  calc & update minDefect []
         {
         minDefect [p] = dayDefect [p];
         }
           minVar = maxDefect[p] - minDefect [p];
           minVarProd = p;
      }
   }
}


void calcTotalDefects( int dayDefect[],  int & ttlDef, int SIZE, int  p, int & d, int & trackDays)
{
   cout << "\n\n\n\nTotal number of defects: " << ttlDef;   
}


void totalProductDefects (int dayDefect[], int totalDefect[], int i, int SIZE, int numProd, int p, int trackDays)
{   
   cout << "\n\n\nTotal defects over " << trackDays << " days for:";
   for ( int d = 1; d <= numProd; d++)    
   {
      cout << "\n\nProduct: " <<  d  << ": ";  
      cout << totalDefect [d];
   }
}


void maxDefects ( int maxDefect [])
{
   int i = 0;
   cout << "\n\nEnter product number: " ;
   cin >> i;
   cout << "\n\nThe maximum number of defects for Product ";
   cout << i << " is: " << maxDefect[i];
}

void minDefects (int minDefect [])
{
int i = 0;
cout << "\n\nEnter product number: " ;
cin >> i;
cout << "\n\nThe minimum number of defects for Product ";
cout << i << " is: " << minDefect[i];
}

void minVariance (int maxDefect [], int minDefect [], int minVarProd, int minVar)
{
   cout << "\n\nThe product with the minimum variance of " ;
   cout << minVar <<  " is Product " << minVarProd;
}

I think you're on the right track with setting minDefect[p] equal to the first dayDefect[p] value, and do the same with the maxDefect[p]. If you were keeping track of this information on paper, you'd write down the dayDefect value for each of the 9 parts, so then your min and max for each of the parts would be equal to that part's dayDefect[p]. New day, new dayDefect[p] values which if they are greater than the old maximum, they are the new maximum, and if they are less than the old minimum they are the new minimum.

Hopefully that's clearer than it seems to be to me hehe.

Thanks! I just can't figure out WHERE to set minDefect to = dayDefect. Everywhere I tried, it gets caught up in the loop and is updated tothe alue of dayDefect at each iteration. How do I initialize minDefect with the FIRST user input values of dayDefect, and then let it carry on from there?

I need more comfort with loops and arrays, but really at this point, I need this done!

I have 2 other issues and then I can put this to rest.

1) I can't get option 6 (min variance - per product) to calculate and display properly. The proscribed output should be:

"The product with the minimum variance of 0 is Product 3."

Poorly written, but there it is.

2) I have to ensure that option 1 (enter data) has run at least once before any other option. If not, I need an error message to loop over, and over...

I can't seem to get these 3 things to work.

Thank you so much!!!

Latest variation on the theme...

#include <cmath>
#include <iostream>
using namespace std;

// Function Prototypes
void displayMenu ();

void enterData (int & numProd, int & trackDays,
                int & numDef, int dayDefect[], int & d, int & ttlDef, 
                int totalDefect[], int maxDefect [], int minDefect [], int  & minVar, int  & minVarProd);

void calcTotalDefects( int dayDefect[],  int & ttlDef,
                      int SIZE, int  p, int & d, int & trackDays);

void totalProductDefects (int dayDefect[], int totalDefect[],
                          int i, int SIZE, int numProd, int p, int trackDays);

void maxDefects ( int maxDefect []);

void minDefects (int minDefect []);

void minVariance (int maxDefect [], int minDefect [], int minVarProd, int minVar);



int main ()
{
   //declare variables

   int ttlDefProd;   // total number of defects, and total defects per product
   int minDef, maxDef;    // minimum, and maximum defects
   int minVarProd;     //  Product with minimum variance
   int choice;              //Menu selection
   int numProd, trackDays, numDef; //number of products, days to track & defects
   int p = 0;    // product
   int d = 0;   // Day
   int ttlDef = 0;
   int i =0;     // defect
   int maxIndex = 0;  
   int minVar;            // minimum variance (valu)
   int data_In;


   // Arrays..............
   const int SIZE = 10;
   int dayDefect [SIZE] = {0};
   int totalDefect [SIZE] = {0};
   int minDefect [SIZE] = {0};
   int maxDefect [SIZE] = {0};

   do    // Runs overall program, regulating menu acccess,
   {       // processing functions, & program exit

      displayMenu ();      //Display options menu function
      cin >> choice;                   //Enter menu choice  
      while (choice < 1 || choice > 7)    //  validate choice............invalid entry
      {
         cout << "\n\n\nInvalid entry.  Please choose from options 1-7.  ";
         cin >> choice;
      }
      if (choice ==1)
         data_In = 1;


      if (choice > 0 && choice < 8)   //............valid choice entry
      {
         //********Menu Switch**********************
         
            switch (choice)                                                      //   choice switch runs the menu.
            {                                                                                //    Each case will call the appropriate
            case 1:   // Enter data                                processing function
               enterData (numProd, trackDays, numDef, dayDefect, d, ttlDef, 
                  totalDefect, maxDefect , minDefect, minVar, minVarProd);
               break;

            case 2:  // Total Defects                                 
               calcTotalDefects( dayDefect,  ttlDef, SIZE, p, d, trackDays);                                                           
               break;                                                                                  

            case 3:   // Total defects per product               
               totalProductDefects (dayDefect, totalDefect, i, SIZE, numProd, p, trackDays);
               break;

            case 4:   // Maximum defects
               maxDefects ( maxDefect);          
               break;

            case 5:  // Minimum defect
               minDefects ( minDefect);
               break;

            case 6:   // Product w/ min variance
               minVariance (maxDefect, minDefect, minVarProd, minVar);
               break;

            case 7:   // Program exit     
               cout << "\n\n\nExiting program. . . ";           
               break;
               // Error check
            }
        
      } 
   }
   while (choice > 0 && choice < 7);



   //**********************************
   return (0);
}

//}

//*******************FUNCTIONS********************************
// Menu Function
void displayMenu ()
{
   cout << "   \n\n\n\n";
   cout << "*                              Main Menu                               *\n";
   cout << "                *****************************************\n\n";
   cout << "                 1. Enter Data\n";
   cout << "                 2. Report: Total number of defects\n";
   cout << "                 3. Report: Total defects per product.\n";
   cout << "                 4. Report: Maximum defects.\n";
   cout << "                 5. Report: Minimum defects.\n";
   cout << "                 6. Report: Product with minimum variance.\n";
   cout << "                 7. Exit\n\n\n";
   cout << "                  Choice:  ";

}


// enterData function
void enterData (int & numProd, int & trackDays,
                int & numDef, int dayDefect[], int & d, int & ttlDef, 
                int totalDefect[], int maxDefect [], int minDefect [], int & minVar, int & minVarProd)       
{
   //enter number of products
   cout << "\n\nEnter number of products: ";
   cin >> numProd;

   while (numProd <2 || numProd > 10)
   {
      cout << "The number of products must be between 2 and 10.\n\n";
      cout << "\n\nRe-enter number of products: ";
      cin >> numProd;
   }

   // enter days to track
   cout << "\n\nEnter number of days to track:  ";
   cin >> trackDays;

   while (trackDays < 2 || trackDays > 7) // error check days to track
   {
      cout << "\n\nThe number of days tracked must be between 2 and 7.";
      cout << "\n\n Re-enter number of days to be tracked: ";
      cin >> trackDays;
   }

   // enter defects per day into dayDefect array
   cout << "\n\nEnter defects for each day. Hit <enter> after each day's entry. ";
   cout << "\n\nDefects must be entered in integer form and separated by a space.";


   for (int d=1; d<=trackDays; d++)
   {
      cout << "\n\nDay " << d<< ": "; 
      for (int p  = 1; p <= numProd; p++)
      {
         cin >>  dayDefect [p];

         ttlDef += dayDefect [p];       //calc total defects

         totalDefect [p] += dayDefect [p];  //calc & update totalDefect[]- (per product)

         if (dayDefect [ p] > maxDefect [p] ) // calc & update maxDefect[]
         {
            maxDefect [p] = dayDefect [p]; 
         }      

         if (dayDefect [p] < minDefect [p] ) //  calc & update minDefect []
         {
            minDefect [p] = dayDefect [p];
         }
         minVar = maxDefect[p] - minDefect [p];  //Calc & update minVar[]
         minVarProd = p;
      }
   }
}


void calcTotalDefects( int dayDefect[],  int & ttlDef, int SIZE, int  p, int & d, int & trackDays)
{
   cout << "\n\n\n\nTotal number of defects: " << ttlDef;   
}


void totalProductDefects (int dayDefect[], int totalDefect[], int i, int SIZE, int numProd, int p, int trackDays)
{   
   cout << "\n\n\nTotal defects over " << trackDays << " days for:";
   for ( int d = 1; d <= numProd; d++)    
   {
      cout << "\n\nProduct: " <<  d  << ": ";  
      cout << totalDefect [d];
   }
}


void maxDefects ( int maxDefect [])
{
   int i = 0;
   cout << "\n\nEnter product number: " ;
   cin >> i;
   cout << "\n\nThe maximum number of defects for Product ";
   cout << i << " is: " << maxDefect[i];
}

void minDefects (int minDefect [])
{
   int i = 0;
   cout << "\n\nEnter product number: " ;
   cin >> i;
   cout << "\n\nThe minimum number of defects for Product ";
   cout << i << " is: " << minDefect[i];
}

void minVariance (int maxDefect [], int minDefect [], int minVarProd, int minVar)
{
   cout << "\n\nThe product with the minimum variance of " ;
   cout << minVar <<  " is Product " << minVarProd;
}

If it's not working to set the initial value inside of your for loop, try it before the for loop. That way it will be assigned for each iteration of the days and not reassigned for each product.

What is the formula you are supposed to use for minVar? I would suspect you would find the mean number of defects and the minimum variance would be the one with the least value for number of errors - mean.

Set a flag (bool value) between your first case statement and the break so it's true once you've run that method. Put an if statement around your switch statement that will only let a selection greater than 1 go through if that flag has been set.

I think I am misunderstanding. I don't know how to code it properly. I tried to put just cin>> dayDefect, then dayDefect = minDefect, immediately following the prompt to enter the number of defects, and it messed up my Day1:, Day2: display.

minVar:
"variance = maximum number of defects – minimum number of defects"
minVar = maxDefect[p] - minDefect [p];

And, what's a bool flag? I tried to look it up, but I'm not quite sure how to implement it. (would never believe I got a 95 on the last exam, huh?)

Thx much!

Just the input/ calc function code...

//enter number of products
   cout << "\n\nEnter number of products: ";
   cin >> numProd;     

   // enter days to track
   cout << "\n\nEnter number of days to track:  ";
   cin >> trackDays;

   // enter defects per day into dayDefect array
   cout << "\n\nEnter defects for each day. Hit <enter> after each day's entry. ";
   cout << "\n\nDefects must be entered in integer form and separated by a space.";
   
   //////  cin >> dayDefect; 
   //////  minDefect[] = dayDefect;    <= I don't get the day1:,etc

   for (int d=1; d<=trackDays; d++)
   {
      cout << "\n\nDay " << d<< ": "; 
      for (int p  = 1; p <= numProd; p++)
      {
         cin >>  dayDefect [p];

         ttlDef += dayDefect [p];       //calc total defects

         totalDefect [p] += dayDefect [p];  //calc & update totalDefect[]- (per product)

         if (dayDefect [ p] > maxDefect [p] ) // calc & update maxDefect[]
         {
            maxDefect [p] = dayDefect [p]; 
         }      

         if (dayDefect [p] < minDefect [p] ) //  calc & update minDefect []
         {
            minDefect [p] = dayDefect [p];
         }
         minVar = maxDefect[p] - minDefect [p];  //Calc & update minVar[]
         minVarProd = p;
      }
   }
}

Yes, I see what you are saying... How about if you put it within the p for loop, but only set maxDefect[p] = dayDefect[p] if it's the first p in the loop.

Set variance initially to maxDefect[1] - minDefect[1] (if it's the first part again, so you can include this one in your if statement from the first issue above) and use something similar to lines 32 through 35. Don't call the variable on line 36 minVar, call it something like Var and find the minimum of the Var values.

bool myFlag = false; //just a boolean value (true or false) in this case the 
//flag is unset, just expressions from old(er) folks

if (selection < 2)
{
   //Run your menu item 1
   myFlag = true;  //set the flag
}
else if(myFlag) //meaning myFlag == true, since it's already boolean
{
  switch(selection)
  {
      case 2: //etc. etc.

   }
}

You get the idea. I'm sure someone is bound to point out a fancier way of doing it, but trace it through by hand to see that if the flag's not set and the menu selection is something else, it will pass right through the if statements and you can loop around again.

Hopefully that leaves you some fun on your own.

Thank you so much for all your help!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.