Error with output
Sep 29, 2014 at 1:16pm Sep 29, 2014 at 1:16pm UTC
Hello everyone, new to the forum. I was trying to complete an assignment but I just can't figure out how to get the output to display in a certain form. Here is the question(calculating distance between entered coordinates): "The display produced by your program should be:
The distance between the points (xxx.xx, xxx.xx) and (xxx.xx,
xxx.xx)is xxx.xxxx"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include<iostream>
#include<iomanip>
#include<cmath>>
using namespace std;
int main()
{
int x1,x2,y1,y2;
cout << "Input coordinate x2: " ;
cin>>x2;
cout << "Input coordinate x1: " ;
cin>>x1;
cout << "Input coordinate y2: " ;
cin>>y2;
cout << "Input coordinate y1: " ;
cin>>y1;
distance=sqrt(pow(x2-x1,2)+(pow(y2-y1,2);
cout <<"The distance between the points: " <<setw(6) << fixed << setprecision(3) <<distance<;
return 0;
}
thanks!
Sep 29, 2014 at 1:19pm Sep 29, 2014 at 1:19pm UTC
1 2 3 4 5
std::cout << std::fixed << std::setprecision(2);
std::cout << "The distance between the points: (" << x1 << ", " << y1 <<
") and ( << x2 << '', " << y2 << ") is " ;
std::cout << std::setprecision(4);
std::cout << distance;
Sep 29, 2014 at 3:02pm Sep 29, 2014 at 3:02pm UTC
Thank you. I must be doing something wrong as I still get error messages. Do I have to alter the code in anyway?
Sep 29, 2014 at 3:58pm Sep 29, 2014 at 3:58pm UTC
Post error messages here
Topic archived. No new replies allowed.