-4
int i;
static int count = 0;
while (1)
{
    cout << "Enter the index number for the product you want to purchase!" << endl;
    cin >> i;
    switch (i)
    {
        case 1:
            count++;
            cout << "stationary box" << "(quantity=)" << count << endl;
            break;
         case 2:
            count++;
            cout << "Remote control car" << "(quantity=)" << count << endl;
            break;
         case 3:
             count++;
             cout << "Magnet" << "(quantity=)" << count << endl;
             break;
    }
        

        
}
Evg
  • 25,259
  • 5
  • 41
  • 83

1 Answers1

1
  • Use three count variables: count 1, count2, count3

  • Then increment them in the switch-case statement according to the input

int i;
int count1 = 0, 
    count2 = 0, 
    count3 = 0;
while (1)
{
    cout << "Enter the index number for the product you want to purchase!" << endl;
    cin >> i;
    switch (i)
    {
        case 1:
            count1++;
            cout << "stationary box" << "(quantity=)" << count1 << endl;
            break;
         case 2:
            count2++;
            cout << "Remote control car" << "(quantity=)" << count2 << endl;
            break;
         case 3:
             count3++;
             cout << "Magnet" << "(quantity=)" << count3 << endl;
             break;
    }     
}
CapTen101
  • 476
  • 6
  • 12