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: -
#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;
-
}
-
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?
5 1379
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: -
#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;
-
}
-
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?
I think you mean prototype, not protocol. Anyways, your problem is that your changeinterger2 function has a prototype instead of a heading. remove the semicolon from that line and put the parameter variables in it. And put the function prototype at the top of your code with the other one.
Also, in both functions you are assigning a variable to a new name and then returning that, this isn't necessary.
Instead of this: - int result = Integer_B;
-
return result;
you could just put this:
And a similar thing with your other function.
Thanks for that. I just did as you said (except for the 'result' part, I will do that later). My code now looks like: -
#include <iostream>
-
using namespace std;
-
-
int ChangeInteger(int, int); // prototype
-
int ChangeInteger2(int, int); // prototype
-
-
int main()
-
{
-
int IntegerA;
-
int IntegerB;
-
-
cout << "Type 1st integer: ";
-
cin >> IntegerA;
-
-
cout << "Type 2nd integer: ";
-
cin >> IntegerB;
-
-
cout << "The value of IntegerA is " << ChangeInteger(IntegerA, IntegerB) << endl;
-
-
system ("pause");
-
-
return 0;
-
}
-
-
int ChangeInteger (int Integer_A, int Integer_B) // definitie
-
-
{
-
int result = Integer_B;
-
return result;
-
}
-
-
{
-
int ChangeInteger2(Integer_A, int Integer_B)
-
-
int IntegerA;
-
int IntegerB;
-
-
cout << "The value of IntegerB is " << ChangeInteger2(IntegerA, IntegerB) << endl;
-
-
int ChangeInteger2 (int Integer_A, int Integer_B) // definition
-
-
int result2 = Integer_A;
-
return result2;
-
}
-
I am still getting a missing function header error on the line with the bracket above: int ChangeInteger2(Integer_A, int Integer_B, int Integer_Temp)
line 33 starts a function definition for
int ChangeInteger2(Integer_A, int Integer_B)
except you have no left brace.
line 40 which is inside (int ChangeInteger2(Integer_A, int Integer_B)
defines
int ChangeInteger2 (int Integer_A, int Integer_B) // definition
again.
It looks like you wanted to call ChangeInteger() inside ChangeInteger2() but didn't code th call correctly.
I still dont understand something, you say I do not have a left brace but on line 32 I have the left brace. Or I am just missing something?
I actually want to have the changeinteger part to be applicable to integer a changing into integer b and I have used the changeinteger2 part to change integer b into integer a.
int ChangeInteger2(Integer_A, int Integer_B)
<<<<<<<<<<<
int IntegerA;
int IntegerB;
cout << "The value of IntegerB is " << ChangeInteger2(IntegerA, IntegerB) << endl;
int ChangeInteger2 (int Integer_A, int Integer_B) // definition
int result2 = Integer_A;
return result2;
}
I don't see a left brace here( <<<<<<).
Plus what is this line for:
int ChangeInteger2 (int Integer_A, int Integer_B) // definition
It looks like:
int ChangeInteger2(Integer_A, int Integer_B)
and the compiler will see it as trying to define a function within a function and what won't compile.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: mwazir |
last post by:
Hi all,
Needed a clarification on a simple point. What is the real difference
between Build and Rebuild option in the .NET IDE and when should either of
the options be used?
I tried searching...
|
by: Rich |
last post by:
I am trying to obtain more debugging information for an issue I
reported (ref. Bug #37185
<http://bugs.php.net/bug.php?id=37185&edit=2>). Unfortunately, I do not
have access to the now-ancient...
|
by: nw |
last post by:
Hi,
I previously asked for suggestions on teaching testing in C++. Based
on some of the replies I received I decided that best way to proceed
would be to teach the students how they might write...
|
by: John Nagle |
last post by:
Back in March, I posted this:
That was for M2Crypto 0.17.
It's still broken in M2Crypto 0.18.
And there's no RPM or Windows binary.
Nobody actually uses this stuff, do they?
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |