Program wont work

I am writing a program that will take in polar or rectangular coordinates and convert them to the other.

This is what i have so far but it will not work and i dont know why:


/* CS150 Assignment 1
9-17-08
The purpose of this program is to convert complex numbers from rectangular to polar form or from polar to rectangular form.
*/
#include<iostream>
#include<cmath>
#include<fstream>
#include<iomanip>
using namespace std;
int main()
{
//declare variable
float choice;
ofstream out_file("Lab1.out");
out_file<<"CS 150 Assignment 1 "
<<"\n9-17-2008\n\nConverting Polar to Rectangular form."<<endl;

//calculate pi
double pi
<<pi == 4*atan(1.0)<< endl;

//input R or P
cout << "Enter R for rectangular or P for polar: ";
cin>>choice;
out_file<<"\n\nUser wants to convert "<<choice<<"\n";

if (choice=='R')
{
double x, y;
cout<<"Enter x and y vector components: "<<endl;
cin>>x>>y;
cout<<"magnitude = " <<sqrt(pow(x,2)+pow(y,2) <<endl;
cout<<"degrees from x axis = " <<(atan2(y/x))*(180/pi) <<endl;
}

else if (choice=='P')
{
double magnitude, degrees;
cout<<"Enter the magnitude and the angle in degrees: "<<endl;
cin>>magnitude<<degrees;
cout<<"x component = " <<cos(degrees*(180/pi))*magnitude <<endl;
cout<<"y component = " <<sin(degrees*(180/pi))*magnitude <<endl;
}


/*
// input a dummy value to freeze the window
char a;
cout<<"\nEnter a character to end program: ";
cin>>a;
return 0;
*/


This is the error messages:

1>d:\my documents\cs150\cs150_assignment_1\project1\project1.cpp(53) : fatal error C1075: end of file found before the left brace '{' at 'd:\my documents\cs150\cs150_assignment_1\project1\project1.cpp(11)' was matched
1>Build log was saved at "file://d:\My Documents\CS150\CS150_Assignment_1\Project1\Debug\BuildLog.htm"
1>Project1 - 55 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Yeah. No wonder it doesn't work.

1
2
double pi
<<pi == 4*atan(1.0)<< endl;
You're using the shift operator (<<) on a double. Its use in a declaration doesn't make any sense, anyway. There's also an equality operator that should be an assignment operator. Then there's that endl. Oh yeah. There's no need to calculate pi each time. 3.141592 will do just fine.

1
2
3
4
float choice;
//...
cout << "Enter R for rectangular or P for polar: ";
cin>>choice;
Do I need to say what's wrong with this?

 
cout<<"magnitude = " <<sqrt(pow(x,2)+pow(y,2) <<endl;

Missing parenthesis.

 
cout<<"degrees from x axis = " <<(atan2(y/x))*(180/pi) <<endl;

atan2() takes two parameters.

 
cin>>magnitude<<degrees;

Oh, come on.

1
2
3
4
// input a dummy value to freeze the window
char a;
cout<<"\nEnter a character to end program: ";
cin>>a;
Don't even get us started. (http://www.cplusplus.com/forum/beginner/1988/ )
Last edited on
Sorry for the obvious errors it my first program and my prof. is basura. I made some changes. He wants us to calculate pi and not use a constant for some reason.

Here is what i have, help would be appreciated.:


/* CS150 Assignment 1 Mike Swagger
9-17-08
The purpose of this program is to convert complex numbers from rectangular to polar form or from polar to rectangular form.
*/

#include<iostream>
#include<cmath>
#include<fstream>
#include<iomanip>
using namespace std;

int main()
{
//declare variable
float choice;
ofstream out_file("Lab1.out");
out_file<<"CS 150 Assignment 1 Mike Swagger"
<<"\n9-17-2008\n\nConverting Polar to Rectangular form."<<endl;

//calculate pi
double pi
pi == (4*atan(1.0))

//input R or P
cout << "Enter R for rectangular or P for polar: ";
cin >> choice;

if ( choice== 'R' )

double x, y;
cout<<"Enter x and y vector components: ";
cin>> x >> y;
cout<<"magnitude = " <<sqrt(pow(x,2))+(pow(y,2));
cout<<"degrees from x axis = " <<(atan2(y/x))*(180/pi);


if ( choice == 'P' )

double magnitude, degrees;
cout << "Enter the magnitude and the angle in degrees: "
cin >> magnitude<<degrees;
cout << "x component = " <<cos(degrees*(180/pi))*magnitude;
cout << "y component = " <<sin(degrees*(180/pi))*magnitude;
None of the mistakes I pointed out were corrected.
I tried to correct all the things you said. but don't understand some of the terminology.
Start here:

http://www.cplusplus.com/doc/tutorial/program_structure.html

Read the rest of the tutorial
Topic archived. No new replies allowed.