1. What would be wrong with not writing return statement in a value returing fun
ID: 3552778 • Letter: 1
Question
1. What would be wrong with not writing return statement in a value returing function? Can you have a return statement in a void function? Does the return statement in the following function cause syntax error?
void p(double x, double y)
{
cout << x << " " << y << endl;
return x+y;
}
2. Write a function headers (not the bodies) for the following functions;
a. Return a sales commission, given the sales amount and the commission rate.
b.Display the calendar for a month, given the month and year.
c.Return a square root of number.
d.Test Whether a number is even, and return true if it is.
e.Display a message a specified number of times.
f.Return the monthly payment, given the loan amount, number of years, and annual interest rate.
g.Return the corresponding uppercase letter, given a lowercase letter.
Please Help me!
Explanation / Answer
1 It will give error.If a function has a return type of ' int ' then it has to return ' int '.
Yes,we can have a return statement in void function but it should not return any value.instead return is used in this case to return to the calling statement. for example,,,,
void print_no_less_than_ten()
{
int i=0;
while(1)
{
i++;
cout << i<<endl;
if(i>=9) return;
}
}
NOw, the function in your case gives an error because return type is void but your function tries to return double.
2......
a) double sales_comm( double sales amount, double comm_rate)
b) void display(int month, int year)
c)double sq_root(double num)
d) bool test_even(int num)
e)void display(int num, string msg)
f)double payment(double loan_amount, int num_year, double rate)
g)char upper(char lower)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.