C++ program to check percentage of a student and display the division (distinction, first, second, third or fail) scored using switch case
int main() is a function.
A function is like a machine which takes something from us (not necessarily) and then performs an operation on it.
int main() means that the function main gives us an integer.
return 0; — The function main returns an integer value (int main()), therefore here we are returning 0. return is a keyword which is used to return some value from a function. It indicates that our program has been run successfully and we terminate our main function with this return statement.
float percentage;
float -float is used for display the numbers as a decimal value.While integer(int) only displays the rounded value.
cout<<”Enter your percentage”;
<< is the output operator.
cin>>percent;
>> is the input operator.
Switch Case:
switch(expression)
{
case constant1:
statement(s);
break;
case constant2:
statement(s);
break;
/* you can give any number of cases */
default:
statement(s);
}
In switch…case, the value of the expression enclosed in the brackets ( ) following switch is checked. If the value of the expression matches the value of the constant in case, the statement(s) corresponding to that case will be executed.
No need to enter break for the default case.
x=percent/10;
X is checked in the switchcase. If the value matches the value of the constant in case ,the statement corresponding to that case will be executed.
Code:
Output:
Refer GUVI for learn more about C++.