Find the errors in the following c program This program dis
Find the errors in the following c++ program.
// This program displays the sum of the numbers 1-100.
#include<iostream>
using namespace std;
int main()
{ int count = 1, total;
while (count <= 100)
total += count;
cout << \"The sum of the numbers 1-100 is \";
cout << total << endl;
return 0;
}
Solution
Please initialize total = 0 otherwise default random number will be assigned to total.
#include<iostream>
using namespace std;
int main()
{ int count = 1, total = 0;
while (count <= 100)
total += count;
cout << \"The sum of the numbers 1-100 is \";
cout << total << endl;
return 0;
}
