编写程序,读入几个具有相同ISBN的交易,输出所有的读入交易的和,关键是如何控制读入的信息条数,假设我就读入两条信息,就要输出结果,亦或是三条
#include<iostream>#include"Sales_item.h"
int main()
{
Sales_item total,book;
std::cout<<"enter some transactions:"<<std::endl;
if(std::cin>>total)
{
while(std::cin>>book)
{
if(total.same_isbn(book))
{
total+=book;
}
else
{
std::cout<<"have different isbn"<<std::endl;
return 1;
}
}
std::cout<<"ISBN,number of copies sold,"
<<"total revenue,and average price are:"
<<std::endl<<total;
}
else
{
std::cout<<"no data"<<std::endl;
return -1;
}
return 0;
}