(C++) AVERAGE FINDER PROGRAM USING C++ FOR BEGINNERS. A PROGRAM TO FIND AVERAGE USING C++.

Pv



 (C++) AVERAGE FINDER PROGRAM USING C++ FOR BEGGINERS. A PROGRAM TO FIND AVERAGE USING C++.



SO IN THIS TUTORIAL WE ARE GOING TO MAKE A PROGRAM TO FIND AVERAGE OF SOME NUMBERS USING C++. THIS IS FOR WHO ARE BEGGINER IN C++. IN THIS PROJECT WE WILL USE FOR LOOP AND IF-ELSE STATEMENT. IT WILL WE VERY EASY TRUST ME. OK, SO LETS START.


START WITH THIS-
#include <iostream>
using namespace std;
int main()
{

NOW WE ARE CREATING SOME VARIABLES AND ASSIGNING THEIR VALUE-
    int tonu;
    double eachnu[100], allsum = 0.0, average;
* WE HAVE MADE AN ARRAY (eachnu).

TAKE TOTAL NUMBER OF DATA-
    cout << "ENTER TOTAL NUMBER OF DATA : ";
    cin >> tonu;

THEN A IF STATEMENT-
    if (tonu > 60 || tonu <= 1)
    {
        cout << " ERROR !!!" << endl;
        cout << " ENTER NUMBER UPTO 60 FROM 2.";
        cin >> tonu;
    }
EXPLANATION OF ABOVE IF STSTEMENT-
* IF USER ENTER 1 OR BELOW TWO IT WILL ASK AGAIN FOR DATA.
* IF USER ENTER NUMBER OVER 60 THEN ALSO IT WILL ASK FOR DATA.

A ELSE STATEMENT-
    else
    {

A FOR LOOP TO TAKE AND ADD VALUES-
        for (int i = 0; i < tonu;)
        {
            i++;
            cout << "ENTER " << i << " number :    " << endl;
            cin >> eachnu[i];
            allsum += eachnu[i];
        }
EXPLANATION-
* FIRSTLY WE HAVE MADE A VARIABLE I AND SET IT VALUE 0, AND i < tonu.
*  i++ TO ADD 1 EACH TIME THE LOOP RUNS.
* THEN MAINLY TAKING NUMBER AND SETING THEM IN ARRAY WE HAVE MADE EARLIER.
* FINALLY ADDING THEM TO ALLSUM(allsum).

THEN CALCULATING AND SHOWING AVERAGE.
average = allsum / tonu;
cout << endl;
cout << "AVERAGE OF " << tonu << " NUMBERS IS :  "<<average<< endl;

THEN ENDING THE ELSE STATEMENT AND THE PROGRAM-
    }
        return 0;
    }


FULL SOURCE CODE-
#include <iostream>
using namespace std;
int main()
{
    int tonu;
    double eachnu[100], allsum = 0.0, average;
    cout << "ENTER TOTAL NUMBER OF DATA : ";
    cin >> tonu;
    if (tonu > 60 || tonu <= 1)
    {
        cout << " ERROR !!!" << endl;
        cout << " ENTER NUMBER UPTO 60 FROM 2.";
        cin >> tonu;
    }
    else
    {
        for (int i = 0; i < tonu;)
        {
            i++;
            cout << "ENTER " << i << " number :    " << endl;
            cin >> eachnu[i];
            allsum += eachnu[i];
        }
        average = allsum / tonu;
        cout << endl;
        cout << "AVERAGE OF " << tonu << " NUMBERS IS :  " << average << endl;
    }
    return 0;
}













Tags

Post a Comment

0Comments

Please Select Embedded Mode To show the Comment System.*