Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 using namespace std;

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Logic In Databases International Workshop Lid 96 San Miniato Italy July 1 2 1996 Proceedings Lncs 1154

Authors: Dino Pedreschi ,Carlo Zaniolo

1st Edition

3540618147, 978-3540618140

More Books

Students also viewed these Databases questions

Question

Define Management by exception

Answered: 1 week ago

Question

Explain the importance of staffing in business organisations

Answered: 1 week ago

Question

What are the types of forms of communication ?

Answered: 1 week ago

Question

Explain the process of MBO

Answered: 1 week ago