Calculating Sums in C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Calculating Sums in C++

I am not quite grasping calling voids in C++ and could use some help (without the “voids” in the example, the solution is correct): #include <iostream> #include <string> using namespace std; //complete the function void int add(int x, int y) { return x+y; } //overload it to sum doubles void double add(double x, double y) { return x+y; } int main() { //calling cout<<add(5,6)<<endl; cout<<add(1.2, 6.5); return 0; }

25th May 2022, 3:01 AM
Kyle P
2 Answers
+ 3
Void means it will return nothing. You can't name a function "void int" or "void double". A function in C++ must have only one return type.
25th May 2022, 3:51 AM
Jack Lama
+ 1
How could it be void and int in the same time ?!! You must declare the function either void or int/ double/ float .... Etc
25th May 2022, 7:30 AM
Mohamed
Mohamed - avatar