Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sedricbenson

macrumors newbie
Original poster
Jan 31, 2006
10
0
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

What are the functions that i should be including?? please help

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....
 
Is this your homework?

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

Nuc
 
sedricbenson said:
1. Input a value in degrees, convert it to radians, compute and print the sine, cosine, and tangent of that angle.
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)].

2. Evaluate the polynomial x3 -3X + 2 for a given value of x.
This is just a basic math operation. Exponents are done with pow(double, double).

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.
This is just a statement. Nothing to solve.

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.
Again, more basic operation. Try using the mod operator (%).
 
sedricbenson said:
What are the functions that i should be including?? please help

Sounds like what you need to do is write your own functions...

sedricbenson said:
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.....

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.
 
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;
float radians;

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

// Convert degrees to radians. Find: sin, cos, tan
degrees = 2 * Pi
degrees = 0.0174532925 radians ;
[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;
}
 
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.
 
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??
 
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 answer;
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;
}
 
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
 
sedricbenson said:
// Compute//
quarters = ammount/.25;
dimes = ammount/.25/.10;
nickels = ammount/.25/.10/.05;
pennies = ammount/.25/.10/.05/.01;


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.
 
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??
 
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().
 
T-Stex said:
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().


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.
 
Ooops... Disregard that last post...

// Convert degrees to radians. Find: sin, cos, tan
degrees = 2 * Pi
degrees = 0.0174532925 radians ;
[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.
 
still....

i can't even get the program to run yet because of the parse errors, and yes their still there :confused:
 
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?
 
T-Stex said:
Do sin(double), etc. actually print out numbers?
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.
 
ChrisBrightwell said:
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.

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.
 
Ok

T-Stex said:
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.


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
 
I think the problem is that you're trying to make that a carbon app when it is obviously a console application. Try using the C++ Tool template XCode has and paste your code into that.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.