The switch statement is designed to solve what kind of probl

The switch statement is designed to solve what kind of problem? Can if-else if statement be used to solve the same problem? Write a C^++ statement for the following algebraic expression: g = h + 12/4k The following program has one or more errors. First circle the errors. Then rewrite the corresponding statement(s) to correct the error(s) on the right side.

Solution

solution:

given program


//include #include<iostream> otherwise cin,cout won\'t work it shows compiletime error (cout,cin not declared in this //scope)
using namespace std;

void main() //syntax error write int main()
{
   double num1,num2,sum;
   cout<<\"enter a number\";
   cin>>num1;
   cout<<\"enter a number\";
   cin>>num2;
num1+num2=sum;//result should be left assignment
   cout<<\"sum\"<<sum;
  
}

correct program
#include<iostream>
using namespace std;

int main()
{
   double num1,num2,sum;
   cout<<\"enter num1\";
   cin>>num1;
   cout<<\"enter num2\";
   cin>>num2;
   sum=num1+num2;
   cout<<sum;
   return 0;
}

output

enter num1

10

enter num2

20

sum 30

to find the expression value


#include<iostream>
#include<math.h>
using namespace std;

int main()
{
   double g,h,k,t,s,m,a;
  
  
   cout<<\"enter h value\ \";
   cin>>h;
   cout<<\"enter k value\ \";  
       cin>>k;
cout<<\"enter the value of a\";
cin>>a;

t=h+12;//to find h+12 value
s=pow(a,10); //to compute the power of a^10
m=4*k*s; //to calculate the 4k*a^10
g=(t+m)/(4*k);//to find the g value
cout<<\"the given expression result is\ \"<<g;

}

output

enter h value

3

enter k value

6

enter a value

4

the given expression result g is 1.04858e+006

the differences between switch and if-else ladder

1)switch works faster than if-else.it takes expression and quickly jump starts execution .

2)if more statements to evaluate use switch rather than if-else ladder

3)to execute flat expressions use if-else ladder

4)simple or few number of expressions use if-else ladder

5)switch gives more performance when compare with if-else ladder

 The switch statement is designed to solve what kind of problem? Can if-else if statement be used to solve the same problem? Write a C^++ statement for the foll
 The switch statement is designed to solve what kind of problem? Can if-else if statement be used to solve the same problem? Write a C^++ statement for the foll

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site