Answer to Question #233147 in C++ for alex

Question #233147

Explanation of the program

[Explain (where applicable)

l  how the number of decimal point was set

 

l · function(s) that was taken from library & which library

 

l · the logical path of if/else, switch structure

 

l · choice of loop (why for loop or while loop)

1
Expert's answer
2021-09-08T06:57:28-0400

1) float or double when you need a floating point number (with decimals), like 9.99 or 3.14515.

float myNum = 5.75;
cout << myNum;

2) pow() is function to get the power of a number, but we have to use #include<math.h> in c/c++ to use that pow() function. 

#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    double x = 6.1, y = 4.8;
 
    // Storing the answer in result.
    double result = pow(x, y);
 
    // printing the result upto 2
    // decimal place
    cout << fixed << setprecision(2) << result << endl;
 
    return 0;
}

3) Use the if statement to specify a block of C++ code to be executed if a condition is true.

int time = 20;
if (time < 18) {
  cout << "Good day.";
} else {
  cout << "Good evening.";
}

4) The while loop loops through a block of code as long as a specified condition is true:

int i = 0;
while (i < 5) {
  cout << i << "\n";
  i++;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS