3

I am doing the problem 1.22 in the book of C++ primer 5th edition. I want to read several Sales_item objects until I don't want to put in more. I don't know how to tell the terminal that I think it's time to end, I don't want to put in more.

I tried to type in "*" or any other thing which is not a Sales_item object. But the program never ends.

#include <iostream>
#include "Sales_item.h"

int main() {
  Sales_item item;
  while (std::cin >> item)
      item += item;
  std::cout << item << std::endl;
  return 0;
}

I expect when I type something that is not a Sales_item object, I could get a sum-up Sales_item object and get out of the program.

crashmstr
  • 28,043
  • 9
  • 61
  • 79
Veronica
  • 43
  • 5

0 Answers0