Advertisement
Ronaldoztupang

Debug Program C++ #1 FIX

Jul 4th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. /*Fix the errors and get an error free compilation and execution.*/
  2.  
  3. #include<iostream>
  4. #include<fstream>
  5. #include<string>
  6. #include<math.h>
  7. using namespace std;
  8. /*  Udacity Lesson 3: Arithmetic Operations
  9.     Date : 04/07/2019
  10.     No : 14
  11. */
  12. int main()
  13. {
  14.     ifstream myfile;
  15.     myfile.open ("input.txt");
  16.     int coeff1, coeff2, constant;
  17.     int exp1, exp2;
  18.     int y;
  19.     int x;
  20.     //Calculate the value of y for a user defined three term polynomial
  21.     //Get the coefficients, exponents, and the constants
  22.     std::cout<<"What is the first coefficient?";
  23.     std::cin>>coeff1;
  24.     std::cout<<coeff1<<"\n";
  25.     std::cout<<"What is the exponent of the first term?";
  26.     std::cin>>exp1;
  27.     std::cout<<exp1<<"\n";
  28.     std::cout<<"What is the second coefficient?";
  29.     std::cin>>coeff2;
  30.     std::cout<<coeff2<<"\n";
  31.     std::cout<<"What is the exponent of the second term?";
  32.     std::cin>>exp2;
  33.     std::cout<<exp2<<"n";
  34.     std::cout<<"What is the constant?";
  35.     std::cin>>constant;
  36.     std::cout<<constant<<"\n";
  37.     //Print the complete equation
  38.     std::cout<<"The polynomial we are solving is:\n";
  39.     std::cout<<"coeff1"<<"*x^exp1"<<" + "<<"coeff2"<<"*x^"<<"exp2"<<"+ "<<"constant";
  40.     std::cout<<"\nWhat is the value of x?";
  41.     std::cin>>x;
  42.     std::cout<<x<<"\n";
  43.     //Solve the equation with the given x
  44.     y = coeff1*pow(x,exp1) + coeff2*pow(x,exp2)+constant;    
  45.     std::cout<<"y = ("<<coeff1<<"*"<<x<<"^"<<exp1<<") + ("<<coeff2<<"*"<<x<<"^"<<exp2<<") + "<<constant<<" = "<<y;
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement