N
nvangogh
Hi, I have a program (an exercise from C++ primer) which should be
really easy, but I cannot work out the solution.
The program should take input until control-d is hit. It should continue
to read transactions so long as the user inputs them.
This is the program but it only takes one transaction. In an earlier
program I was able to use while(std::cin >> book) as the loop condition.
But this condition does not work with this program.
Can you tell me what you think?
#include <iostream>
#include <string>
struct Sales_data
{
std::string bookNo;
unsigned units_sold = 0;
double revenue = 0.0;
};
int main()
{
Sales_data item;
// I want to loop this - what condition can i use?
std::cout << "Input ISBN: Units Sold: Price per unit" << std::endl;
std::cin >> item.bookNo >> item.units_sold >> item.revenue;
std::cout << item.bookNo << '\t' << item.units_sold << '\t' <<
item.revenue * item.units_sold << std::endl;
return 0;
}
really easy, but I cannot work out the solution.
The program should take input until control-d is hit. It should continue
to read transactions so long as the user inputs them.
This is the program but it only takes one transaction. In an earlier
program I was able to use while(std::cin >> book) as the loop condition.
But this condition does not work with this program.
Can you tell me what you think?
#include <iostream>
#include <string>
struct Sales_data
{
std::string bookNo;
unsigned units_sold = 0;
double revenue = 0.0;
};
int main()
{
Sales_data item;
// I want to loop this - what condition can i use?
std::cout << "Input ISBN: Units Sold: Price per unit" << std::endl;
std::cin >> item.bookNo >> item.units_sold >> item.revenue;
std::cout << item.bookNo << '\t' << item.units_sold << '\t' <<
item.revenue * item.units_sold << std::endl;
return 0;
}