Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. //Creating the function of average before the main program
  6. int average (int a, int b)
  7. {
  8. int r = a / b;
  9. return r;
  10. }
  11.  
  12. //This is an example of how you would declare an object in a C++ program.
  13. class Box {
  14. public:
  15. double length; // Length of a box
  16. double width; // width of a box
  17. double height; // Height of a box
  18. };
  19.  
  20. //This is the main program that takes the stores works with the user's input/output
  21. int main() {
  22.  
  23. //Declaring the variables
  24. int amount;
  25. int age;
  26. string name;
  27. int total = 0;
  28. int averagenum;
  29.  
  30. //Outputting a line. "\n" is used to skip a line.
  31. cout << "How many people would you like to calculate the average age for?\n";
  32.  
  33. //Inputting a value into a variable.
  34. cin >> amount;
  35.  
  36. //This is an example of a counted loop.
  37. for (int i = 1; i<=amount; i++)
  38. {
  39. cout << "\n";
  40. cout << "Insert the name of person #" << i << "!\n";
  41. cin >> name;
  42. cout << "Insert the age!\n";
  43. cin >> age;
  44.  
  45. //This is a whole line of output that holds variables as well as text. These variables and text are joined together using "<<"
  46. cout << "The name is " << name << " and the age is " << age << "!\n";
  47.  
  48. total = total + age;
  49. averagenum = average (total , i);
  50. cout << "The average age is " << averagenum << "\n";
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement