I almost figured this out but I need help

Write your question here.
I have this mostly figured out, but I do not know why it's not letting me execute the equation when I type it in and give me the output needed. What else do I need to add?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  #include <cstdlib> 
#include <iostream> 
#include <iomanip> 
#include <cmath>

using namespace std; 

int main()
{
    double mass;
    double velocity;
    double momentum;
    double kenergy;
    
    cout << "How much mass:"; 
    cin >> mass; 
    cout << "How much velocity:"; 
    cin >> velocity; 
    
    momentum = mass * velocity;
    kenergy = kinetic(mass, velocity);
    
    return 0; 
}



The problem given is:
You will need to include the iomanip library, as well as the iostream library, for this problem.

In classical physics:
momentum is mass times velocity ( m * v )
kinetic energy is one half the mass times the square of the velocity ( m * v2 / 2 )
Prompts the user for the mass and the velocity as input.
Use double variables.
Then compute the momentum and kinetic energy.
Print the momentum and the kinetic energy with identifying text.
The execution result should have six lines 1) input mass, 2) input velocity, 3) output mass, 4) output velocity, 5) momentum, 6) kinetic energy.
Round the printed values to two decimal positions and align the decimal points.

Test data, run the program twice:
First test input 5.0 kilograms and 4.0 meters per second
Second test input 3.15 kilograms and 10.0 meters per second
Note: With the input in kilograms and meters per second, the units for the momentum is Kg m/s and for Kinetic energy is Joules.
What does not let execute which equation?

Your only outputs are on lines 15 and 17. You are supposed to output four values.

Where is the function "kinetic"?
I guess I stated it wrong. What do I write in order for what I type in for the cout response to be input into the equation I gave?

I modified it a bit:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  #include <cstdlib> 
#include <iostream> 
#include <iomanip> 
#include <cmath>

using namespace std; 

int main()
{
    double mass;
    double velocity;
    double momentum;
    double kenergy;
    
    cout << "How much mass:"; 
    cin >> mass; 
    cout << "What is the velocity:"; 
    cin >> velocity; 
    
    momentum = mass * velocity;
    kenergy = mass * velocity^2 * 0.5;
    
    return 0; 
}
I don't understand what you are asking? Looks to me like all you need to is output back to the user your findings...Am I missing something?
The execution result should have six lines 1) input mass, 2) input velocity, 3) output mass, 4) output velocity, 5) momentum, 6) kinetic energy


1
2
3
4
5
6
7
8
9
10
11
cout << "Input mass: "; cin >> mass;
cout << "Input velocity: "; cin >> velocity;
cout << "The mass is: " << mass << endl;
cout << "The velocity is: " << velocity << endl;
//Calculations
momentum = mass * velocity;
kenergy = mass * velocity^2 * 0.5;

cout << "The momentum is: " << momentum << endl;
cout << "The kinetic energy is: " << kenergy << endl;
cout << "End of program.." << endl;


I think it also says:
Round the printed values to two decimal positions and align the decimal points.


You will need to use setprecision for this. Here is an example of how setprecision works.

1
2
3
4
5
6
7
8
9
10
11
12
13
// setprecision example
#include <iostream>     
#include <iomanip>      

int main () {
  double f =3.14159;
  cout << setprecision(5) << f << '\n';
  cout << setprecision(9) << f << '\n';
  cout << fixed;
  cout << setprecision(5) << f << '\n';
  cout << setprecision(9) << f << '\n';
  return 0;
}

Output of the above example:
1
2
3
4
3.1416
3.14159
3.14159
3.141590000


Also notice the difference of the output when using fixed versus when not using fixed

Lastly, I have NO idea what you are doing when you say velocity^2 . This isn't WolphramAlpha, in C++ you will have to use the pow function. Instead what you are doing is shifting the Most Significant Bit to the left using the ^ operator.
Last edited on
Topic archived. No new replies allowed.