Why to put last statement in loops for fetching classes in C++? -


so i'm bit confused section in c++ primer 5th of lipmann. here's sample code: http://imgur.com/a/6pbmx author refered last statement before ending "if" used perform last transaction. don't @ all, when try put comment mark beside it, nothing happend, program still works. i'm sorry bother if obvious because i'm extremely new in programming. idea or example of logical path highly appreciated

#include <iostream> #include "sales_item.h" int main() {    sales_item total; // variable hold data next transaction    // read first transaction , ensure there data prc    if (std::cin >> total) {       sales_item trans; // variable hold running sum       // read , process remaining transactions       while (std::cin >> trans) {           // if we're still processing same book           if (total.isbn() == trans.isbn())           total += trans; // update running total           else {               // print results previous book               std::cout << total << std::endl;               total = trans; // total refers next book           }      }      std::cout << total << std::endl; // print last transaction (!!!)    } else {         // no input! warn user         std::cerr << "no data?!" << std::endl;         return -1; // indicate failure    }    return 0; 

}


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -