Question

C++ Identify and explain the error in the following:    float doubleCost(float cost)    { float...

C++

Identify and explain the error in the following:

   float doubleCost(float cost)
   { float cost;
return 2*cost;
   }

0 0
Add a comment Improve this question Transcribed image text
Answer #1
float doubleCost(float cost){
        float cost;                     //cost has been passed as an argument. You are redefining here.
                                                //Error at this line. Since, cost is already a local variable for 
                                                //this function, you cannot redefine it. It becomes confusing for 
                                                //the compiler, hence it will raise error.
        return 2*cost;
}
Add a comment
Know the answer?
Add Answer to:
C++ Identify and explain the error in the following:    float doubleCost(float cost)    { float...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • a) Explain the concepts of Fixnum and Bignum in Ruby b) Explain the concepts of Float::EPSILON, Float::MIN, and Float::MAX in Ruby c) Explain and exemplify the inclusive range and exclusive range in R...

    a) Explain the concepts of Fixnum and Bignum in Ruby b) Explain the concepts of Float::EPSILON, Float::MIN, and Float::MAX in Ruby c) Explain and exemplify the inclusive range and exclusive range in Ruby d) Describe the concept of dynamic typing in Ruby e) Explain the meaning of variables and the role and applicability of the following program: def trace return unless $trace p @a / p @b / p @c end f) Show a short program that defines a hash...

  • Find the error in each of the following c++ program segments and explain how the error...

    Find the error in each of the following c++ program segments and explain how the error can be corrected. And rewrite the program appropriately using c++ a. int g(void){ cout<<”Inside function g”<<endl; int h(void) {             cout<<”Inside function h”<<endl; }                         } int sum(int x, int y){ int result; result = x+y;                         } void f(double a); {             float a;             cout<<a<<endl; }

  • Consider the following code: 1. float foo (int a, int b, int c, int d, float...

    Consider the following code: 1. float foo (int a, int b, int c, int d, float e) { 2. float e; 3. if (a == 0) { 4. return 0; 5. } 6. int x = 0; 7. if ((a==b) || ((c == d) && bug(a) )) { 8. x=1; 9. } 10. e = 1/x; 11. return e; 12. } Function bug(a) should return a value of true when passed a value of a=1. Build: • a test suite...

  • Java Programming Language: Find the compiling error in the following code segment. Explain what the problem...

    Java Programming Language: Find the compiling error in the following code segment. Explain what the problem is and how to fix it. public class Mark { private float value;        public float Mark(float startValue) {        value = startValue; } }

  • Why float f = 10d will cause the compiler error/ and why int and double did...

    Why float f = 10d will cause the compiler error/ and why int and double did not cause any compiler error ? public class Main { public static void main(String[] args) { // write your code here char c = 38; int i = 'a'; double d = 10f; double d2 = 10; float f = 10d; System.out.println(a + b); } }

  • using C , comments will be appreciated. Question1 Write down an function named bitwisedFloatCompare(float number1, float...

    using C , comments will be appreciated. Question1 Write down an function named bitwisedFloatCompare(float number1, float number2)that tests whether a floating point number number1is less than, equal to or greater than another floating point number number2, by simply comparing their floating point representations bitwise from left to right, stopping as soon as the first differingbit is encountered. The fact that this can be done easily is the main motivation for biased exponent notation. The function should return 1 if number1...

  • Explain why the following if statement results in syntax error in C, Java, and C#? if...

    Explain why the following if statement results in syntax error in C, Java, and C#? if (x==1) y = 2 else y = 3;

  • Identify a logical error in the following code and fix it. public class test1 {    ...

    Identify a logical error in the following code and fix it. public class test1 {     public static void main(String[] args){         int total;         float avg;         int a, b, c;         a=10;         b=5;         c=2;         total=a+b+c;         avg=total/3;         System.out.println("Average: "+avg);     } } Answer: Write the output of the program below. import java.util.Scanner; public class test2 { public static void main(String[] arg){ int psid; String name; Scanner input=new Scanner(System.in); System.out.println("Enter your PSID"); psid=input.nextInt(); System.out.println("Enter your...

  • ​​​​​​ 11.   A _____________ error does not cause the compiler to generate an error, but does...

    ​​​​​​ 11.   A _____________ error does not cause the compiler to generate an error, but does cause the program to produce incorrect results. Syntax, logic, variable name, function name 12.   A syntax error occurs when the programmer violates one or more grammar rules of the C language. True or False 13.   Given this line of code: y = sqrt(x); x would be known as the argument. True or False 14.   A void function does not return a value to the...

  • Identify the errors in this C program (struct - calculating volume, area of cylinder). Explain. #include...

    Identify the errors in this C program (struct - calculating volume, area of cylinder). Explain. #include <stdio.h> #define PI 3.14 typedef struct cylinder{    float r,h;    float areacircle=2*PI*r;    float areacylinder;    float volumecylinder;    areacylinder=2*PI*r*h+2*PI*r*r;    volumecylinder=PI*r*r*h; }; int main() {    float start,numcyls;    printf("How many cylinders do you want? Enter a positive integer.\n");    scanf("%f",&numcyls);    if(numcyls<1||ceilf(numcyls)!=numcyls)    while()    {printf("The number you have entered is not a positive integer. Please try again.\n");        printf("Remember,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT