Q:

Write a program that reads several transactions for the same ISBN. Write the sum of all the transactions that were read

0

Write a program that reads several transactions for the same ISBN. Write the sum of all the transactions that were read.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

int main()
{
    Sales_item total;
    if (std::cin >> total) {
        Sales_item trans;
        while (std::cin >> trans) {
            if (total.isbn() == trans.isbn())
                total += trans;
            else {
                std::cout << total << std::endl;
                total = trans;
            }
        }
        std::cout << total << std::endl;
    }
    else {
        std::cerr << "No data?!" << std::endl;
        return -1;
    }

    return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now