Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- //Creating the function of average before the main program
- int average (int a, int b)
- {
- int r = a / b;
- return r;
- }
- //This is an example of how you would declare an object in a C++ program.
- class Box {
- public:
- double length; // Length of a box
- double width; // width of a box
- double height; // Height of a box
- };
- //This is the main program that takes the stores works with the user's input/output
- int main() {
- //Declaring the variables
- int amount;
- int age;
- string name;
- int total = 0;
- int averagenum;
- //Outputting a line. "\n" is used to skip a line.
- cout << "How many people would you like to calculate the average age for?\n";
- //Inputting a value into a variable.
- cin >> amount;
- //This is an example of a counted loop.
- for (int i = 1; i<=amount; i++)
- {
- cout << "\n";
- cout << "Insert the name of person #" << i << "!\n";
- cin >> name;
- cout << "Insert the age!\n";
- cin >> age;
- //This is a whole line of output that holds variables as well as text. These variables and text are joined together using "<<"
- cout << "The name is " << name << " and the age is " << age << "!\n";
- total = total + age;
- averagenum = average (total , i);
- cout << "The average age is " << averagenum << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement