When I compile and run the program it won\'t return doubles, I enter 1.0 and it
ID: 3769526 • Letter: W
Question
When I compile and run the program it won't return doubles, I enter 1.0 and it returns 1 etc. any one know what I'm missing?
#include <iostream>
#include <cmath>
using namespace std;
int main(){
double x_Cord= 0.0 ;
double y_Cord= 0.0;
while(x_Cord==0.0 && y_Cord==0.0){
cout<< "Please enter X coordinate: ";
cin>> x_Cord;
cout<< "Please enter Y coordinate: ";
cin>> y_Cord;
double temp=1.0;
if(x_Cord<0.0 && y_Cord<0.0){
cout<<"Point"<< "("<<x_Cord<<","<<y_Cord<<")"<<"is in quadrant III."<<endl;
}
else if(x_Cord>0.0 && y_Cord> 0.0){
cout<<"Point "<< "("<<x_Cord<<","<<y_Cord<<")"<<" is in quadrant I"<<endl;
}
else if(x_Cord>0.0 && y_Cord<0.0){
cout<<"Point "<< "("<<x_Cord<<","<<y_Cord<<")"<<" is in quadrant IV"<<endl;
}
else if(x_Cord<0.0 && y_Cord>0.0){
cout<<"Point "<< "("<<x_Cord<<","<<y_Cord<<")"<<" is in quadrant II."<<endl;
}
else if(x_Cord==0.0 && y_Cord==0.0){
cout<<"Point "<< "("<<x_Cord<<","<<y_Cord<<")"<<" is on the origin."<<endl;;
}
else if(x_Cord==0.0){
cout<<"Point "<< "("<<x_Cord<<","<<y_Cord<<")"<<" is on y-axis"<<endl;
}
else if(y_Cord==0.0){
cout<<"Point is on x-axis"<<endl;}
x_Cord=0.0;
y_Cord=0.0;
}
return 0;
}
Explanation / Answer
#include <iostream>
#include <cmath>
using namespace std;
int main(){
double x_Cord= 0.0 ;
double y_Cord= 0.0;
while(x_Cord==0.0 && y_Cord==0.0){
cout<< "Please enter X coordinate: ";
cin>> x_Cord;
cout<< "Please enter Y coordinate: ";
cin>> y_Cord;
double temp=1.0;
if(x_Cord<0.0 && y_Cord<0.0){
printf("Point (%.2lf,%.2lf) is in quadrant III", x_Cord, y_Cord);
}
else if(x_Cord>0.0 && y_Cord> 0.0){
printf("Point (%.2lf,%.2lf) is in quadrant I", x_Cord, y_Cord);
}
else if(x_Cord>0.0 && y_Cord<0.0){
printf("Point (%.2lf,%.2lf) is in quadrant IV", x_Cord, y_Cord);
}
else if(x_Cord<0.0 && y_Cord>0.0){
printf("Point (%.2lf,%.2lf) is in quadrant II", x_Cord, y_Cord);
}
else if(x_Cord==0.0 && y_Cord==0.0){
printf("Point (%.2lf,%.2lf) is on the origin.", x_Cord, y_Cord);
}
else if(x_Cord==0.0){
printf("Point (%.2lf,%.2lf) is on y-axis", x_Cord, y_Cord);
}
else if(y_Cord==0.0){
printf("Point (%.2lf,%.2lf) is on x-axis", x_Cord, y_Cord);
}
cout<<endl;
x_Cord=0.0;
y_Cord=0.0;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.