我的老師給我這個和我加入爲什麼setprecision會出錯?什麼是setprecision
«setprecision(3) <<setiosflags(ios::fixed) »
你能告訴我爲什麼當一個錯誤?
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;
main()
{
float x1,y1,x2,y2,x3,y3,x4,y4,PQ,QR,RS,SP,Keliling;
cout << "Masukkan koordinat empat titik berbeda (x,y) :\n";
cout<< "P(x,y):" ;
cin >> x1>>y1 ;
cout <<"\n" ;
cout << "Q(x,y) :" ;
cin >> x2>>y2 ;
cout <<"\n" ;
cout << "R(x,y) :" ;
cin>> x3>>y3 ;
cout <<"\n" ;
cout << "S(x,y) :" ;
cin >>x4>>y4;
cout <<"\n" ;
PQ = sqrt(pow(x2-x1,2)+pow(y2-y1,2));
QR = sqrt(pow(x3-x2,2)+pow(y3-y2,2));
RS = sqrt(pow(x4-x3,2)+pow(y4-y3,2));
SP = sqrt(pow(x1-x4,2)+pow(y1-y4,2));
Keliling = PQ+QR+RS+SP;
cout << "Kelilingnya adalah " << Keliling <<" satuan";
«setprecision(3) <<setiosflags(ios::fixed) »
return 0 ;
}
你的老師給你的那個,用引號包圍了代碼。你不熟悉引號嗎? – molbdnilo