Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I add numbers in C++ again?

Seriously, I don’t remember..

Would an integer work??
But I don’t know why its not working…

I’m trying to add integers, like this.

int main() {
   i = 1;
   b = 3;
}
 Signed int addition() {
i + b

}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can’t use functions and variables, including local variables, parameters, etc before they have been declared first. Though, you can initialize variables at the same time you declare them. For example:

#include <iostream>

int addition(int a, int b);

int main() {
   int i = 1;
   int b = 3;
   int sum = addition(i, b);
   std::cout << sum;
}

int addition(int a, int b) {
    return a + b;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading