Sum and Average Calculator in C++ || Switch Case || C++ || Turbo C++
In this we are going to see how to make a very basic Program in C++ to find Sum and Average of two numbers.

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

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

void main()
{
        clrscr();
	int a, b, c, sum, d;
	float avg;
	cout << "Enter 3 numbers" << endl;
	cin >> a >> b >> c;
	cout << "Now select what do you want" << endl;
	cout << " 1. Average \n 2. Sum \n";
	cin >> d;
	switch (d)
	{
	case 1:
		avg = (a + b + c) / 3;
		cout << "The average of the numbers is : " << avg;
		break;

	case 2:
		sum = a + b + c;
		cout << "The sum of the numbers is : " << sum;
		break;
	}
	getch();
}
    
    

The code given below can be used for g++/gcc Compiler:-

#include<iostream>
using namespace std;

int main()
{
	int a, b, c, sum, d;
	float avg;
	cout << "Enter 3 numbers" << endl;
	cin >> a >> b >> c;
	cout << "Now select what do you want" << endl;
	cout << " 1. Average \n 2. Sum \n";
	cin >> d;
	switch (d)
	{
	case 1:
		avg = (a + b + c) / 3;
		cout << "The average of the numbers is : " << avg;
		break;

	case 2:
		sum = a + b + c;
		cout << "The sum of the numbers is : " << sum;
		break;
	}
	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