An efficient way to read your variables (#24844)
* An efficient way to read your variables Instead of declaring the variable "grade" in a trivial way by giving it value directly from code, we can enter it when we run the program, to make our code more dynamic and testing multiple situations by just re-running the program and entering a different thing as an input, instead of modifying the variable over and over again * Cleaned up comment
This commit is contained in:
@ -43,6 +43,11 @@ int main () {
|
||||
// local variable declaration:
|
||||
char grade = 'D';
|
||||
|
||||
/* You can also have the user enter the value of grade to make your code more dynamic, like so:
|
||||
char grade;
|
||||
cin >> grade;
|
||||
*/
|
||||
|
||||
switch(grade) {
|
||||
case 'A' :
|
||||
cout << "Excellent!" << endl;
|
||||
@ -63,7 +68,7 @@ int main () {
|
||||
cout << "Your grade is " << grade << endl;
|
||||
|
||||
return 0;
|
||||
}```
|
||||
}
|
||||
|
||||
Output:
|
||||
You passed
|
||||
|
Reference in New Issue
Block a user