Example 2 if else statement:
statement:
Write a program in c++ that input your marks and calculate your percentage if percentage is less than 33 then it display that “sorry you are fail” otherwise you it show the message “congratulation you are pass” . your total marks is 850?
Write a program in c++ that input your marks and calculate your percentage if percentage is less than 33 then it display that “sorry you are fail” otherwise you it show the message “congratulation you are pass” . your total marks is 850?
Logic:
The main logic
in this example we calculate the percentage by arithmetic operation. So the
question is how to calculate the percentage ?? for this we divide the input
marks by total marks and multiply it 100 then we get the percentage. Then we
use if else condition
Program:
#include "stdafx.h"
#include "iostream"
#include"conio.h"
using namespace std;
void main()
{
float marks,t_marks;
float percentage;
t_marks=850;
cout<<"enter the marks==";
cin>>marks;
percentage= (marks/t_marks)*100;
if(percentage<33)
cout<<"sorry you are fail";
else
cout<<"congrates you are pass";
_getch();
}
DOWNLOAD SOURCE CODE
0 comments:
Post a Comment