My first function – C++ Program

What it does: 

Just a simple function which I created where it uses parameter. Within the function 1 is added onto the variable which is then returned. Within the main the variables value is set to 20, therefore it is going to increment to 21 once the function is added on. At the end of the program the variable is printed out.

Code:

#include <iostream>
using namespace std;
int AddOne(int start)
{
  int newnumber;
  newnumber = start + 1;
  return newnumber;
}//AddOne
int main()
{
  int testnumber;
  int result;
  testnumber = 20;
  result = AddOne(testnumber);
  cout << result << endl;
  return 0;
}//main

2 thoughts on “My first function – C++ Program

  1. Happy to see a new programmer in town. Wish you all success. Since I don’t see python in the list above (I hope to see you).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s