Customizable training materials to learn C++

Nano teach C++ found result for your search here:

C++ Compute the Sum and Average of Two Numbers

This program takes in two integers x and y as a screen input from the user.
The sum and average of these two integers are calculated and outputted using the ‘cout’ command.
Example:
#include<iostream>
using namespace std; 

int main(){ 

    int x,y,sum;
    float average;
    cout << "Enter 2 integers : " << endl;
    cin>>x>>y;
    sum=x+y;
    average=sum/2;
    cout << "The sum of " << x << " and " << y << " is " << sum << "." << endl;
    cout << "The average of " << x << " and " << y << " is " << average << "." << endl;
    system("pause");

}
Program Output:
Enter 2 integers :
12
15
The sum of 12 and 15 is 27.
The average of 12 and 15 is 13.

No comments:

Post a Comment