Find as many errors as you can and rewrite the function correctly. void total (i
ID: 3939177 • Letter: F
Question
Find as many errors as you can and rewrite the function correctly. void total (int value 1, value2, value3) {return value 1 + value2 + value3:} double average(int value 1, int value2, int value3) {double average; average = value1 - value2 + value3/3;} void area (int length = 30. int width) {return length * width;} void getValue(int value&) {count value&;} Assume the declarations: void Combine(stnng, char, double&, int&); char ch string str double z; sting and which calls are invalid, which calls will lose significant data and why? Valid Invalid Why ans = Combine("a'. "hello", z, x, y), Combine (str, ch, 14, 15.3, 5.4); Combine ("hi", 'b', z, x, 9); Combine(str, ch, x, z, y) if(Calculate(4, 5.5.3)>0) ans = "positive"; while(Combine(4, 5.5.3) > 0)) coutExplanation / Answer
//change return type to int as function is returning int
//add data type as int to value2 and value 3 as it will throw unknown data type error
int total(int value1, int value2, int value3)
{
return value1+value2+value3;
}
//add return average statement as mentiod function is returning double in function statement
double average(int value1, int value2, int value3)
{
double average;
//put braces else it will add value3/3 to value1+value2 which is not an average
average= (value1+value2+value3)/3;
return average;
}
//change void to int as return type
//cannot instantiate arguments of function
int area(int length,int width){
return length*width;
}
//& will be to data type not constant
void getValue(int& value)
{
cout << "Enter a value";
cin >>value;
}
a)Invalid as function return type is void,Arguments order is invalid
b)Invalid cannot pass value to &referenced data type
c)Invalid cannot pass value to &referenced data type
d)valid
e)valid
f) invalid as it is infinite loop
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.