# {{{DESPERATE HELP with X-Code}}}

Discussion in 'macOS' started by sedricbenson, Jan 31, 2006.

1. ### sedricbenson macrumors newbie

Joined:
Jan 31, 2006
#1
Hi, i am trying to make 4 simple programs that include mathematical functions and cannot seem to either include the right functions or find the appropriate directory to include in my program. I am using Carbon Application builder and want to make a program with the ability to do this:

1. Input a value in degrees, convert it to radians, compute and print the sine, cosine, and tangent of that angle.

2. Evaluate the polynomial x3 -3X + 2 for a given value of x.

3. Given two resistors: if they are connected in series the total resistance is R1+R2. and if they are connected in parallel the total resistance is R1*R2/R1 + R2.

4. Given an amount of money between one penny and one dollar, show how to make up that amount in the least number of coins.

example: 17 cents is 0 quarters
1 dime
1 nickel
2 pennies

i am using #include <Carbon/Carbon.h> and #include <math.h> and I'm also using #include <fp.h> these are supposed to be the correct mac functions to work, but i still can't make it work. PLEASE HELP me, i need to get them finished by tomorrow.....

Thanks....

2. ### Nuc macrumors 6502a

Joined:
Jan 20, 2003
Location:
TN
#2

Sounds pretty cool I'd like to hear the answer... You should have started your homework sooner I know I never do

Nuc

3. ### ChrisBrightwell macrumors 68020

Joined:
Apr 5, 2004
Location:
Huntsville, AL
#3
The conversion is a simple multiplication, but you'll have rounding errors.

360 degrees = 2 * Pi, or 1 degree = 0.0174532925 radians

From there, sin / cos / tan are just basic API calls [sin(double), cos(double), tan(double)].

This is just a basic math operation. Exponents are done with pow(double, double).

This is just a statement. Nothing to solve.

Again, more basic operation. Try using the mod operator (%).

4. ### johnnybluejeans macrumors 6502

Joined:
Jan 16, 2006
Location:
New York, NY
#4
Sounds like what you need to do is write your own functions...

Again, your terminology seems a bit off here.. the #include statements are for loading libraries. Certainly you will probably want the Carbon and math libraries to write a carbon based app for doing some math.

I think the idea here is that you are supposed to figure out the math yourself, and write a program to do it.

5. ### sedricbenson thread starter macrumors newbie

Joined:
Jan 31, 2006
#5
Hey, thanks for all your help you guys....But i still can't get the program to run. I'm working with C++ on Windows platform and am just trying to learn it on the Mac also, things are a little bit different, but I personally love the mac. Please bare with me.....

Here is my program....Can anyone please tell me why it is not working....

#include <Carbon/Carbon.h>
#include <CoreServices/CoreServices.h>
#include <math.h>

int main(void)

{
// Declare varibles
float Pi = 3.14159265358979323846264338;
float degrees;

// Enter the angle in degrees and the program will convert it to radians
printf ("\n Please enter a number\n ");

// Convert degrees to radians. Find: sin, cos, tan
degrees = 2 * Pi
[sin(double), cos(double), tan(double)] ;

// report result
printf("\n The number %i degrees is equal to %i radians. \n" ,
"This number can be shown as %i sin, %i cos, %i tan." degrees, radians, sin, cos, tan\n\n);

// All finished
// Call the event loop
RunApplicationEventLoop();

return 0;
}

6. ### johnnybluejeans macrumors 6502

Joined:
Jan 16, 2006
Location:
New York, NY
#6
So what is happening when you run it?

You say your working with c++ on Windows...? You aren't trying to compile this under windows are you? You can't compile an application for a Mac under windows.

7. ### sedricbenson thread starter macrumors newbie

Joined:
Jan 31, 2006
#7
no, i'm working on a mac and only mac, but our class is dealing with how to perform this program on Windows using C++

If you copy the program i made and put it in x-code under carbon application, it will give you like 3 errors, i don't know what a "parse error is" and how to fix the other errors so my program will run...

try putting the program i included in my quote above and you'll see the errors i mean

thanks so much for your help....maybe you can help me solve this once and for all

also,,,,,,,

I have another program i'm building for class, and it is not giving me the correct output. I want to break down a sum of money into how many quarters/dimes/nickels/pennnies are in it. Run this program and you'll see the errors i'm getting....can you help??

8. ### sedricbenson thread starter macrumors newbie

Joined:
Jan 31, 2006
#8
here's the program of the money question

#include <Carbon/Carbon.h>
#include <CoreServices/CoreServices.h>
#include <math.h>

int main(void)

{
// Declare varibles//
float ammount;
float quarters;
float dimes;
float nickels;
float pennies;

// Enter the angle in degrees and the program will convert it to radians//
printf ("\n Please enter an ammount of money: \n ");
scanf ("%i", &ammount);

// Compute//
quarters = ammount/.25;
dimes = ammount/.25/.10;
nickels = ammount/.25/.10/.05;
pennies = ammount/.25/.10/.05/.01;

// report result//
printf("\n The ammount of %i can be broken down into %i quarters, %i dimes, %i nickels, %i pennies. \n\n",
ammount, quarters, dimes, nickels, pennies);

// All finished//
// Call the event loop//
RunApplicationEventLoop();

return 0;
}

9. ### T-Stex macrumors 6502

Joined:
Jan 15, 2006
Location:
Pennsylvania
#9
What Errors?

What exactly are the errors that you're getting? What lines are they on, and what kind of errors? If you post a listing of the errors, they'll be easier to understand

10. ### T-Stex macrumors 6502

Joined:
Jan 15, 2006
Location:
Pennsylvania
#10

Correct me if I'm wrong, but you might want to try declaring quarters, dimes, etc. as ints. Then, using integer division, you'll divide the amount of money by .25, which will be the number of quarters. Then, subtract the amount in quarters from the total amount, i.e... amount -= quarters*.25;. Then repeat those steps with the new amount, dividing by .10 for dimes, and so on.

11. ### sedricbenson thread starter macrumors newbie

Joined:
Jan 31, 2006
#11
errors list

oh i'm sorry:

here they are:

on line 21 i get an error saying: parse error before "radians"

on line 22 i get an error saying: parse error before "double"

and on line 26 i get an error saying: parse error before "degrees"

on the money problem, if i put a decimal in the number (like \$2.53) i get some really large answers, i'm wondering if i should be using a different identifier under where it says //declare variables. Maybe something like float, or double, or int...would using any of those help to solve my problem??

12. ### T-Stex macrumors 6502

Joined:
Jan 15, 2006
Location:
Pennsylvania
#12
Try using double everywhere there's a float maybe? Otherwise it looks like it should work. Also, I don't know if this has anything to do with it, but I don't think you need the "void" as a parameter for main().

13. ### sedricbenson thread starter macrumors newbie

Joined:
Jan 31, 2006
#13

yes, but even changing everything to "float" and taking out "void" it gives me this answer:

[Session started at 2006-01-31 23:45:11 -0500.]

Please enter an ammount of money:
3.5

The ammount of 918028288 can be broken down into 0 quarters, 920125440 dimes, 0 nickels, 923664384 pennies.

14. ### T-Stex macrumors 6502

Joined:
Jan 15, 2006
Location:
Pennsylvania
#14
Ooops... Disregard that last post...

// Convert degrees to radians. Find: sin, cos, tan
degrees = 2 * Pi
[sin(double), cos(double), tan(double)] ;

That's where your problems are. You just need one statement that says something like "radians = (degrees * [whatever the conversion is] );". I'm not sure what the next like with the sin, cos, and tan actually does, but I'm not so sure that it looks correct. Do sin(double), etc. actually print out numbers? If not, then you'll have to set them each equal to a value, and print out that value later on.

15. ### sedricbenson thread starter macrumors newbie

Joined:
Jan 31, 2006
#15
Parse Errors???

do you know what the parse errors on the other program are for yet??

16. ### sedricbenson thread starter macrumors newbie

Joined:
Jan 31, 2006
#16
still....

i can't even get the program to run yet because of the parse errors, and yes their still there

17. ### T-Stex macrumors 6502

Joined:
Jan 15, 2006
Location:
Pennsylvania
#17
I think those parse errors are in my previous post. I'm not sure about the money problem though, i'm not too familiar with the scanf function so I'm not quite sure how it works, but maybe that's why?

18. ### T-Stex macrumors 6502

Joined:
Jan 15, 2006
Location:
Pennsylvania
#18
Put a semicolon after Pi on line 20 or 22 or whatever it is.

EDIT: The next two lines need to be fixed too.

19. ### ChrisBrightwell macrumors 68020

Joined:
Apr 5, 2004
Location:
Huntsville, AL
#19
They return double values.

To the OP, I was offering hints, not solutions. Cutting and pasting what I gave you, as you learned, will not solve your problem. They're enough to point you in the right direction, but it sounds like all you're doing is stabbing in the dark.

20. ### T-Stex macrumors 6502

Joined:
Jan 15, 2006
Location:
Pennsylvania
#20
Agreed. I think you should have enough here to get your project finished, and if not, just hand in what you have done, and talk to your teacher/professor about helping you out.

21. ### sedricbenson thread starter macrumors newbie

Joined:
Jan 31, 2006
#21
Ok

Ok thanks guys really appreciate the help, i'll see what i can do...

Thanks for all your help I really appreciated it. I think it should make sense now..

Have a nice evening...

Sedric