Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
lol k so i did this code up

Code:
#include <iostream>
using namespace std; 
#include <cmath>

double polar (double &, double &);

int main ()
{
	double r, angle;
	
	cout << "Enter two numbers for polar coordinates: " << endl;
	cin >> r, angle; 
	polar (r, angle);
	cout << "The corresponding rectangular coordinates are (" << x << ", " << y << ")"
	
	return 0; 
}

double polar (double & r, double & angle) 
{
	double x, y; 

	x = r* cos (angle);
	y = r * sin (angle);
	
	return x, y;
}

To satisfy this question:


11 Define a function that can convert the polar coordinates into rectangular coordinates, that is input two real numbers, r and θ, and return two numbers, x and y, according to the following formula:
y = r sin theta, x = r cos theta
You must use reference parameters to return two values. Then write a program that will prompt user to input two numbers, call the function and output the results. The sample output is
Enter two numbers for polar coordinates: 3.5 20
The corresponding rectangular coordinates are (3.19531, 1.42829)


my question is.. what exactly did i do wrong? i am still pretty rough on user defined functions.. and i thought i was doing so well!!! but it doesnt work.. says use of undeclared indentifier x and y. disappointing.
 
Hint. Pass by value those things you don't want/need to change in the function and pass by reference those things you do want/need to change. How many variables altogether do you need to pass to your function? What data type does it need to return?

B
 
Hint. Pass by value those things you don't want/need to change in the function and pass by reference those things you do want/need to change. How many variables altogether do you need to pass to your function? What data type does it need to return?

B

im pretty sure it needs to return double, right? and altogether i need to pass 2 values?? im confused so im not sure..
 
Break the problem down.

You need to pass r and angle. Do you need to change their values? You also need to return x and y, both doubles. How might you do that if the function can only return a single value?

B
 
Break the problem down.

You need to pass r and angle. Do you need to change their values? You also need to return x and y, both doubles. How might you do that if the function can only return a single value?

B

r and angle are going to have to have their values changed right? why can the function only return a single value? and on top of that, HOW might i do that? lol ugh

----------

The problem statement says:



So I would guess no.

B

correct :)

----------

so am i at least on the right track here? i feel useless haha
 
So have we found out a program that allows a Mac to run C++, because when I get into coding I want to know if I will have to buy a PC or not. I love Macs and I hope Apple starts making them more compatible with things.
 
So have we found out a program that allows a Mac to run C++, because when I get into coding I want to know if I will have to buy a PC or not. I love Macs and I hope Apple starts making them more compatible with things.

This is what I used: https://github.com/kennethreitz/osx-gcc-installer
Or you can download xcode, you definitely won't need to buy a PC.

----------

Were you given any examples of using pass by reference?

no not really just a comparison between pass by reference and pass by value that makes minimum sense. i dont get anything out of lecture, i learn everything in lab because my lab instructor knows what she is talking about, but sadly this assignment is due before the correspondng lab.
 
This is what I used: https://github.com/kennethreitz/osx-gcc-installer
Or you can download xcode, you definitely won't need to buy a PC.

----------



no not really just a comparison between pass by reference and pass by value that makes minimum sense. i dont get anything out of lecture, i learn everything in lab because my lab instructor knows what she is talking about, but sadly this assignment is due before the correspondng lab.
Thanks ill download that. and yeah I already have Xcode and I have only used it about 2 times.
 
Code:
void give_me_a_number(int & number)
{
     number = 5;
}

... somewhere in deep cyberspace someone writes ...

Code:
int number_given;
give_me_a_number(number_given); 

std::cout << "I was given the number: " << number_given << "\n";
 
does anyone know if they make an ffviewer for mac yet??

----------

If you have Xcode you already have gcc/clang and can compile C++. No need to download install anything else.

B
oops and ok good. i wasn't sure if Xcode could code C++

----------

Xcode vs GCC? which one is better?
 
:( i feel so lost and discouraged now i thought things were going so well. its so frustrating not to be able to do something
 
Xcode is an IDE, gcc is a collection of compilers (gcc = GNU compiler collection) that is used by some versions of Xcode. The newest versions of Xcode are migrating to clang instead of gcc.

B
im going to stick with Xcode. by the way, does anyone use Coda here?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.