Variables working

Filip 831 Reputation points
2020-12-28T19:25:33.297+00:00

Hi.
What can I do to fix this code?

include <iostream>

using namespace std;
int main()
{
int a=10;
cout<<a<<endl;
change();
cout<<a<<endl;
return 0;
}

void change(){
a=a+10;
}

Thanks

Community Center | Not monitored
0 comments No comments
{count} votes

Accepted answer
  1. JamesTran-MSFT 36,906 Reputation points Microsoft Employee Moderator
    2020-12-28T23:12:34.847+00:00

    @Filip
    Thank you for your post! You can try the below to fix your code.

    #include <iostream>  
    using namespace std;  
      
    int change(int num1);  
      
      
    int main()  
    {  
        int a = 10;  
        int changeNumber;  
      
        cout << a << endl;  
        changeNumber = change(a);  
        cout << changeNumber << endl;  
        return 0;  
      
    }  
      
      
    int change(int a) {  
        int changed = a + 10;  
      
        return changed;  
    }  
    

    51774-image.png

    Thank you for your time and patience throughout this issue.

    ----------

    Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.