Help with a for() loop in a structure

I have an assignment to create a CandyBar structure with the members: Name, Weight and Calories. The problem I am having is we are to use a dynamic array and prompt the user for the max amount of candy bars they would like to input overall and then loop through all the candy bars until we reach that amount. In my for() loop i get to the very first prompt and then an "Exited with non zero status" error code. (we also were asked to use a menu)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  #include <iostream>
#include <string>

using namespace std;


struct CandyBar{
  string name;
  double weight;
  int calories;
};

void cbcMenu();
int getChoice();


int main()
{
 int choice;
 int CANDY = 0;
 
 do
 {
   cbcMenu();
   choice = getChoice();
   
   if (choice != 4)
   {
     if (choice == 1)
     {
       cout << "Enter the total amount of candy bars you wish to input: " << endl;
       cin >> CANDY;
       
       CandyBar * candy = new CandyBar[CANDY];
       
       for (int i = 0; i < CANDY; i++)
       {
         cout << "Enter the name of a candy bar: ";
         getline(cin, candy[CANDY].name);
         cout << "Enter the candy bars weight: ";
         (cin >> candy[CANDY].weight).get();
         cout << "Enter the candy bars calories: ";
         (cin >> candy[CANDY].calories).get();
       }
       
       
       
     }
   }
 }while (choice != 4);
}





//Menu for program
void cbcMenu()
{
  cout << "Pick an option from the menu below.\n";
  cout << "1.  Add Candy\n";
  cout << "2.  Delete Candy\n";
  cout << "3.  Display Candy\n";
  cout << "4.  Quit\n";
}


//Function to make sure you can choose only 1-4 in menu
int getChoice()
{
  int choice;
  cin >> choice;
  
  while (choice < 1 || choice >4)
  {
    cout << "You can only choose options 1-4. Please re-enter. ";
    cin >> choice;
  }
return choice;
}
So I just realized I totally goofed and in my loop candy[CANDY] should have been candy[i] instead...swapped it and it started working just perfectly, now to move on the the rest of the code and hopefully no more errors.
Topic archived. No new replies allowed.