Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you use a function inside another function?
    primarykey
    data
    text
    <p>I have two .cpp files, one called practice.cpp, and the other called adder.cpp. they are both inside the Source Files folder.</p> <p>the fists code is shown below:</p> <pre><code>// adder.cpp #include "stdafx.h" //include library int addition(int a, int b) //start function { int r = 0; //declare variables r = a + b; //actual code return r; //output of function } </code></pre> <p>The second code:</p> <pre><code>// Practice.cpp #include "stdafx.h" #include "adder.cpp" #include &lt;iostream&gt; using namespace std; int main(void) { int number1 = 0; int number2 = 0; int number3 = 0; do { printf("\n\nInsert value for first number\n\n"); scanf("%d",&amp;number1); printf("\nthe value "); printf("%d ",number1); printf("has been stored in memory location "); printf("%d",&amp;number1); printf("\n\nInsert value for second number\n\n"); scanf("%d",&amp;number2); printf("\nthe value "); printf("%d ",number2); printf("has been stored in memory location "); printf("%d",&amp;number2); number3 = addition(number1,number2); printf("%d",number3); } while (1==1); return 0; } </code></pre> <p>But the code will not compile. I get the error:</p> <pre><code>1&gt;------ Build started: Project: Practice, Configuration: Debug Win32 ------ 1&gt; Practice.cpp 1&gt;c:\users\craig\documents\3rd year work\progamable systems\practice\practice\practice.cpp(25): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1&gt; c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(304) : see declaration of 'scanf' 1&gt;c:\users\craig\documents\3rd year work\progamable systems\practice\practice\practice.cpp(33): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1&gt; c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(304) : see declaration of 'scanf' 1&gt;Practice.obj : error LNK2005: "int __cdecl addition(int,int)" (?addition@@YAHHH@Z) already defined in adder.obj 1&gt;C:\Users\Craig\Documents\3rd year work\Progamable Systems\Practice\Debug\Practice.exe : fatal error LNK1169: one or more multiply defined symbols found ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== </code></pre> <p>I've been looking all over the web, but it looks like i'm doing it correctly. What can I do to fix this? Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload