I think my WHILE loop is wrong somewhere....

The program runs just fine, I have a while loop that keeps asking the person for the price and weight of an item. The loop works fine, but when i put 'N' in order to quit the loop, it quits the whole program instead of going onto the next function.

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
This is the whole function with the loop.

  int getItemsInfo(float& totPrice, int& totWeight)
{
  char choice;
  float price;
  int weight;

  cout << "\n Do you want to order an item? Enter Y or N: ";
  cin >> choice;

  while(choice == 'Y' || choice == 'y')
    {
      cout << "Please enter the price: " << endl;
      cin >> price;
      cout << "Please enter the weight: " << endl;
      cin >> weight;
      
      totPrice += price;
      totWeight += weight;
      
      cout << "\n Do you want to order another item? Enter Y or N: ";
      cin >> choice;
    }
}
can you upload your whole program here?
i dont see any problem in this func
int getItemsInfo(float& totPrice, int& totWeight)
This function is designed to return an integer. There is no return statement in the function.
However, as Lorence30 says, without the context within which this function is called, it is not clear what the effect of this return value is on the calling function.
Topic archived. No new replies allowed.