In one C++ Program translate the following algebraic equations into C++ code. Then run the program with the given values stated below for x and y. Make sure that your results match the output as shown below. The values for x and y should be entered by the user using cin for input.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
usingnamespace std;
int main(void)
{
double x = 0.0;
double R;
cout << fixed << setprecision(2) << endl;
cout << "Enter value for x: " << endl;
cin >> x;
R = 3 * x * x + 5 * x + 1;
cout << endl;
return 0;
}
I have not started the second question but this is what I have for the first Homework question. When I run the program, it asks me for an input and when I type the input in, nothing happens. I am new to C++ coming from python.
#include <iostream>
#include <iomanip>
#include <string>
//#include <fstream> // <--- Not used in what you have
usingnamespace std; // <--- Best not to use.
int main(void)
{
double x{}; // <--- ALWAYS initialize all your variables.double R{};
cout << fixed << setprecision(4) << endl;
cout << "Enter value for x: " << endl;
cin >> x;
R = 3 * x * x + 5 * x + 1;
cout << R <<'\n';
return 0; // <--- Not required, but makes a good break point for testing.
}
Running this gives an output of 61.3887. Is that what you expect? Cut to 2 decimals it is: 61.39.
what does x2 mean?
x^2 probably..?
if you simplify the second one first its a little shorter.
t = x*x-12*x;
result is (t +27)/t+36);
the smallest format for math is not usually the best for c++, sometimes expanding it out makes it easier to translate.