Solve this c++ program...on fatal errror | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Solve this c++ program...on fatal errror

#include <iostream> #include <conio.h> using namespace std; int main() { { int i= 1, sum = 0; clrscr(); while(i++ <= 5) { cout<< '\n'<<i; S += i; } { cout << "\nvalue of the variable i after executing the while loop.." <<i<<"\nsum:...” <<s; return 0; }

12th Sep 2018, 6:53 AM
Legent Mady
Legent Mady - avatar
2 Answers
+ 8
#include <iostream> #include <conio.h> using namespace std; int main() { int i = 1, sum = 0; while(i++ <= 5) { cout << '\n' << i; sum += i; } cout << "\nvalue of the variable i after executing the while loop.." << i << "\nSum: " << sum << endl; return 0; }
12th Sep 2018, 7:06 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 5
Use sum where you have used S and s. If you want the value of i to be displayed from 1 to 5 (not from 2 to 6) do the incrementing inside the loop towards the end rather than in the loop condition.
12th Sep 2018, 8:25 AM
Sonic
Sonic - avatar