Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Code won't compile

+2 votes
asked Apr 28, 2018 by anonymous
I can't get this code to compile:

#include<iostream>
using namespace std;

void readinput(int n1, int n2);
void swap(int n1, int n2);
void toprint(int n1, int n2);

int main()
{
    int n1;
    int n2;
    
    readinput(n1,n2);
    swap(n1,n2);
    toprint(n1,n2);
}
void readinput(int &n1, int &n2)
{
    n1 = 10;
    n2 = 5;
}
void swap(int &n1, int &n2)
{
    int temp;
    temp = n1;
    n1 = n2;
    n2 = temp;
}
void toprint(int n1, int n2)
{
    cout<<n1<<" "<<n2<<"\n";
}

1 Answer

0 votes
answered Apr 28, 2018 by anonymous
you forgot to put & in your signature of function.
Here is working example of yours.

https://onlinegdb.com/H1jesQW6f
commented Apr 28, 2018 by anonymous
Thank you very much!
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...