Just wondering if anyone can help me with this? write a procedural program that
ID: 2267806 • Letter: J
Question
Just wondering if anyone can help me with this?
write a procedural program that prompts the user for a set of Using this information, coordinates follow by a single character If the character is an ‘R' or ‘r', the coordinates should be interpreted as a set ofRectangular Coordinates and t Coordinates he program should calculate and display the equivalent Polar If the character is a 'P' or 'p', the coordinates should be interpreted as a set of Polar Coordinates and the program should calculate and display the equivalent Rectangular Coordinates If the character is anything other than a 'P·p', 'R' or ‘r, the program should display an error message and then terminate See the example outputs shown below: R Problems eTasks Console X Properties Debugger Console terminated> (exit value: 0) Projects.exe IC/C++ Application] CAUsersIghzit Enter The Coordinates Followed by R/r or P/p 10 20 r Rectangular..: (10.0e, 20.08) R ProblemsTasks Console X Properties Debugger Console terminated> (exit value: 0) Projects.exe [C/C++ Application] CUsers ghzit Enter The Coordinates Followed by R/r or P/p 25 60 p Rectangular (12.50, 21.65) R Problems Tasks Console X Properties Debugger Console terminated> (exit value: 0) Projects.exe [C/C+ Application C:Users Enter The Coordinates Followed by R/r or P/p -10 30 R Rectangular..: (-10.00, 30.00) EL Problems eTasksConsoles O Properties (i Debugger Console (exit value: 0) Projects.exe [C/C+Application C:Users ghzit Enter The Coordinates Followed by R/r or P/p 40 -125 P Rectangular..: (-22.94, -32.77) R. Problems eTasksConsole Properties Debugger Console (exit value: 0) Projects.exe [C/C++Application CUsers ghzit Enter The Coordinates Followed by R/r or P/p 3 4 K ERROR!!!Explanation / Answer
#include #include int main () { double i1,i2; double r,t,x,y; char c; printf("Enter the Co-ordinates followed by R/r or P/p "); scanf("%lf %lf %c",&i1,&i2,&c); if (c=='r' | c=='R') { x=i1; y=i2; r=(x*x)+(y*y); r=sqrt(r); t=atan(y/x); printf("Rectangular...:(%.2lf %.2lf) ",x,y); printf("Polar.........:(%.2lf %.2lf) ",r,(t*180)/3.14159); } else if (c=='p' | c=='P') { r=i1; t=i2; x=r*cos((t*3.14159)/180); y=r*sin((t*3.14159)/180); printf("Rectangular...:(%.2lf %.2lf) ",x,y); printf("Polar.........:(%.2lf %.2lf) ",r,t); } else { printf("ERROR!!!! "); } return 0; }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.