#include <iostream>
usingnamespace 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 assigning 'y' in the line 5, but it doesn't runs without showing any error.
Please explain me why have we assinged 'y' to character choice before while loop.
lets say you didnt. what value would it have? certainly not y. so if it didnt have Y or y it wouldnt go into the loop. you made a mistake in the condition btw. it should be choice=='y'||choice=='Y'
In the line 14, the user must enter any variable, then where will it store? and why do we need to include character 'y' only inside while loop (i.e., filled in choice)?