Pass or Fail Program in C++ || Functions || Conditional Statements || Functions || C++
In this, we are going to see Functions, the program is based on function which Calculates, Profit or Loss.

The code given below can be used for TURBO C++ Compiler:-

#include<iostream.h>
#include<conio.h>

int english,maths,physics,chemistry,biology,total;

void get_marks()
{
    cout<<"\nEnter the marks of each subjects out of 20\n";
    cout<<"English:   ";
    cin>>english;
    cout<<"Maths:     ";
    cin>>maths;
    cout<<"Physics:   ";
    cin>>physics;
    cout<<"Chemistry: ";
    cin>>chemistry;
    cout<<"Biology:   ";
    cin>>biology;
}

void calculate_total()
{
    total = english + maths + physics + chemistry + biology;
}

void pass_or_fail()
{
    if(total>40 || total==40)
    {
        cout<<"Your total is "<<total<<" you are Passed. Enjoy!!";
    }

    else
    {
        cout<<"Your total is "<<total<<" you are Failed. Study hard and score good next time!";
    }
}

void main()
{
    clrscr();
    get_marks();
    calculate_total();
    pass_or_fail();

    getch();
}
	
    
The code given below can be used for g++/gcc Compiler:-

#include<iostream>
using namespace std;

int english,maths,physics,chemistry,biology,total;

void get_marks()
{
    cout<<"\nEnter the marks of each subjects out of 20\n";
    cout<<"English:   ";
    cin>>english;
    cout<<"Maths:     ";
    cin>>maths;
    cout<<"Physics:   ";
    cin>>physics;
    cout<<"Chemistry: ";
    cin>>chemistry;
    cout<<"Biology:   ";
    cin>>biology;
}

void calculate_total()
{
    total = english + maths + physics + chemistry + biology;
}

void pass_or_fail()
{
    if(total>40 || total==40)
    {
        cout<<"Your total is "<<total<<" you are Passed. Enjoy!!";
    }

    else
    {
        cout<<"Your total is "<<total<<" you are Failed. Study hard and score good next time!";
    }
}

int main()
{
    get_marks();
    calculate_total();
    pass_or_fail();

    return 0;
}
	
    
#ENJOY CODING

 

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post