Question
I'm getting an error on this code and can't figure it out, I'll post the question as well so you can correct anything I've messed
I'm getting an error on this code and can't figure it out, I'll post the question as well so you can correct anything I've messed up.
This is C++ using visual studio.
Question:
Write a program, which will invoke two functions from the main() with same name but different signature to practice the function overload.
Two methods are: int Same (int a, int b) and int Same (int a, int b, int c)
The first method should cause printing out Divisible if a is divisible by b, otherwise the method should return the remainder. The second method should return the average of a, b and c.
Hint: you might need type casting.
Code:
#include
int main() { int a = 1; int b = 4; int c = 8; int rem; int avg;
rem = Same(a, b); avg = Same(a, b, c); return 0; }
int Same(int a, int b) { if (a % b == 0)cout << "Divisible" << endl; else return a % b; }
int Same(int a, int b, int c) { return (a + b + c) / (float)3; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started