jeudi 4 mai 2017

Show variable at every iteration

#include <iostream>
using namespace std;

int main() {
    int sum(1), count(1);
    while (count <= 6) {
        sum += (2*count + 1);
        count++;
    } 
    cout << "sum = " << sum << endl; 

    return 0;
}

I have this C++ code that is suppose to print the sum of the six consecutive odd numbers, starting  from the number 1. I need to fix it by using a variable tracing cout statement. I want the statement to show what the value of the variable and sum is at each iteration is. Please help.

Aucun commentaire:

Enregistrer un commentaire