I am new to C++ and have learned that when I build a program and I want to learn how, it is best to build each program according to the same standard.
In my programs I want to have a function protocol before the main section and a function definition after the main section.
Now I would like to build a program that takes 2 integers and switches them, integer A becomes integer B and the other way around. Simple.
What I have now is this:
This is not working, it is giving me the following error on the "{" sign that comes below the line with the "int ChangeInteger2 (int Integer_A, int Integer_B, int Integer_Temp)" function definition.
error C2447: '{' : missing function header (old-style formal list?)
By the way, is it good practice to have a protocol and a definition in each program?
In my programs I want to have a function protocol before the main section and a function definition after the main section.
Now I would like to build a program that takes 2 integers and switches them, integer A becomes integer B and the other way around. Simple.
What I have now is this:
Code:
#include <iostream>
using namespace std;
int ChangeInteger(int, int, int); // protocol
int main()
{
int IntegerA;
int IntegerB;
int IntegerTemp;
cout << "Type 1st integer: ";
cin >> IntegerA;
cout << "Type 2nd integer: ";
cin >> IntegerB;
IntegerTemp = 5;
cout << "The value of IntegerA is " << ChangeInteger(IntegerA, IntegerB, IntegerTemp) << endl;
system ("pause");
return 0;
}
int ChangeInteger (int Integer_A, int Integer_B, int Integer_Temp) // definition
{
int result = Integer_B;
return result;
}
int ChangeInteger2(int, int, int); // protocol
{
int IntegerA;
int IntegerB;
int IntegerTemp;
cout << "The value of IntegerB is " << ChangeInteger2(IntegerA, IntegerB, IntegerTemp) << endl;
int ChangeInteger2 (int Integer_A, int Integer_B, int Integer_Temp) // definition
int result2 = Integer_A;
return result2;
}
error C2447: '{' : missing function header (old-style formal list?)
By the way, is it good practice to have a protocol and a definition in each program?
Comment