I saw a C++ program in my C.S. book whose source code is:-
#include <iostream>
using namespace std;
int main()
{
char choice=‘y’; //why is this required?
int marks, classx, test;
while (choice=='y'||choice==‘Y') {
cout<<"Enter marks:";
cin>>marks;
cout<<"\nEnter class:";
cin>>classx;
cout<<"\nWant to Enter more? (y/n)";
cin>>choice; //Can't understand why **choice** is assigned **'y'** before while loop?
}
return 0;
}
In this code, I can't understand why have we assigned the character 'y'
before while
loop. I've omitted the value of choice
which assigns 'y'
in the line 5, but after that it doesn't runs, even without showing any error!
Please explain me why have we assigned 'y'
to character choice
before while
loop.
Please note that I am a newbie to the programming world, and started off with C++