Monday, March 13, 2017

C++ Part 22

While loop Example:

#include <iostream>
using namespace std;
int main( )
{
   int numberOfItems, count,
       caloriesForItem, totalCalories;
   cout << "How many items did you eat today? ";
   cin >> numberOfItems;
   totalCalories = 0;
   count = 1;
   cout << "Enter the number of calories in each of the\n"
        << numberOfItems << " items eaten:\n";
   while (count++ <= numberOfItems)
   {
       cin >> caloriesForItem;
       totalCalories = totalCalories + caloriesForItem;
   }
   cout << "Total calories eaten today = "
        << totalCalories << endl;
   return 0;
}

No comments:

Digital Design Part 3

4th→ assembler translates it to the machine language. 1.6 [20] <§1.6> Consider two diļ¬€erent implementations of the same instru...