This is an archive of a previous version of Sodarace.

Please visit http://sodarace.net for the latest version.

forum  |  »» sodaplay
 
»» forums  »» community discussion forum

subject: Do you want to learn to program in C

357 replies on 24 pages. most recent reply: Tues, Aug 28 10:58 PM by matthew102000

»» back to topic list  

This topic has 357 replies on 24 pages [ « | 1 ... 10 11 12 13 14 15 16 17 18 ... 24  | » ]
»» previous topic   »» next topic  


matthew102000

»» models

Re: Do you want to learn to program in C   posted: 15-Apr-07 01:03   »» 
adding a cylinder area. can anybody find an error. i wont work.

printf("What is the radius of the cylinder???\n \n \t - ");
scanf("%f", &number1);
printf("What is the height of the cylinder???\n \n \t - ");
scaf("%f", &number2);
answer = ((radius * radius) * 3.14) * number2;
printf("%f", answer);

that is just the specific part of the code. no point of posting the entire thing again.

matt wuz here

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 15-Apr-07 01:24   »» 
never mind. got it. sorry for my freak posts.

cactus2

»» models

Re: Do you want to learn to program in C   posted: 15-Apr-07 11:52   »» 
The function for square root is sqrt.

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 15-Apr-07 15:10   »» 
how do you use the sqrt thingy. all i need is an example.

thanks!

matt wuz here

cactus2

»» models

Re: Do you want to learn to program in C   posted: 15-Apr-07 15:16   »» 
double result, input;

result=sqrt(input);

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 15-Apr-07 15:20   »» 
uhh....

i dont get it. a little bigger example please.

matt wuz here

edlinfan

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 15-Apr-07 17:20   »» 
result=sqrt(9)
...
would result in 3 (the square root of nine) being placed into result.

result=sqrt(i)
...
wold result in the square root of i being placed into result.

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 15-Apr-07 20:24   »» 
thanks.

matt wuz here

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 15-Apr-07 20:33   »» 
uhh. this wont work. it sais it has something to do with the system("PAUSE);

#include <stdio.h>
#include <math.h>
int main (void)
{
float diameter, area, radius, circumference, choice;
float number1, number2, number3, answer, choice2;
char function;
printf("SUPER CALCULATOR\n");
printf("------------------------------------\n \n");
printf(" 1 = Circumference of a Circle\n \n 2 = Area of a Circle\n \n");
printf(" 3 = Area of Cylinder\n \n 4 = Cylinder Surface Area\n \n");
printf(" 5 = Area of a Rectangle/Rectangular Prism\n \n 6 = Perimeter of a Rectangle\n \n");
printf(" 7 = Cube Surface Area\n \n 8 = Triangle Area\n \n 9 = Pyramid Area\n \n");
printf(" 10 = ^2 Root\n \n \t - ");
scanf("%f", &choice);
if (choice == (float)1)
{
printf("What is the diameter of the circle?\n \n \t - ");
scanf("%f", &diameter);
circumference = diameter * 3.14;
printf("\n \n \t Circumference = %f units\n \n", circumference);
}
if (choice == (float)2)
{
printf("What is the radius of the circle???\n \n \t - ");
scanf("%f", &radius);
area = (radius * radius) * 3.14;
printf("\n \t Area = %f units^2\n \n", area);
}
if (choice == (float)3)
{
printf("What is the radius of the cylinder???\n \n \t - ");
scanf("%f", &number1);
printf("What is the height of the cylinder???\n \n \t - ");
scanf("%f", &number2);
answer = ((number1 * number1) * 3.14) * number2;
printf("\n %f units^3\n \n", answer);
}
if (choice == (float)4)
{
printf("What is the diameter of the cylinder???\n \n \t - ");
scanf("%f", &number1);
printf("what is the height of the cylinder???\n \n \t - ");
scanf("%f", &number2);
answer = (((number1 * number1) * 3.14) * 2) + (((number1 * 2) * 3.14) * number2);
printf("\n %f units^2\n \n", answer);
}
if (choice == (float)5)
{
printf("What is the width of the rectangle?\n \n \t - ");
scanf("%f", &number1);
printf("What is the height of the rectangle?\n \n \t - ");
scanf("%f", &number2);
printf("Is the figure a rectangular prism? 1 = yes, 2 = no\n \n \t - ");
scanf("%f", &choice2);
if (choice2 == (float)1)
{
printf("What is the length of the rectangular prism?\n \n \t - ");
scanf("%f", &number3);
answer = number1 * number2 * number3;
printf("\n \n \t Area = %f units^3\n \n", answer);
}
if (choice2 == (float)2)
{
answer = number1 * number2;
printf("\n \n \t Area = %f units^2\n \n", answer);
}
}
if (choice == (float)6)
{
printf("what is the width of the rectangle???\n \n \t - ");
scanf("%f", &number1);
printf("what is the height of the rectangle???\n \n \t - ");
scanf("%f", &number2);
answer = (number1 * 2) + (number2 * 2);
printf("\n \n \t Perimeter = %f units\n \n", answer);
};
if (choice == (float)7)
{
printf("what is the width of the rectangular prism???\n \n \t - ");
scanf("%f", &number1);
printf("what is the height of the rectangular prism???\n \n \t - ");
scanf("%f", &number2);
printf("what is the length of the rectangular prism???\n \n \t - ");
scanf("%f", &number3);
answer = ((number1 * number2) * 2) + ((number2 * number3) * 2) + ((number3 * number1) * 2);
printf("\n %f units^2\n \n", answer);
}
if (choice == (float)8)
{
printf("What is the height of the triangle???\n \n \t - ");
scanf("%f", &number1);
printf("what is the width of the triangle???\n \n \t - ");
scanf("%f", &number2);
answer = (number1 * number2) / 2;
printf("\n %f units^2\n \n", answer);
}
if (choice == (float)9)
{
printf("pyramid width\n \n \t - ");
scanf("%f", &number1);
printf("pyramid length\n \n \t - ");
scanf("%f", &number2);
printf("pyramid height\n \n \t - ");
scanf("%f", &number3);
answer = (number1 * number2 * number3) / 2;
printf("\n %f units^3\n \n", answer);
}
if (choice == (float)10)
{
printf("number\n \n \t - ");
scanf("%f", &number1);
answer = sqrt(number1);
printf("%f", answer);
}
}
system("PAUSE");
return 0;
}

what is wrong?

matt wuz here

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 15-Apr-07 21:01   »» 
never mind. got it. extra curly brace `}'

matt wuz here

ROBO_HEN5000

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 15-Apr-07 21:06   »» 
You have to "#include <stdlib.h>" at the top, because the system() function is in that file.

-----COMING SOON-----
I am going to (try to) re-structure the calculator so that it has a function for each choice, that way it will be easier to add functions to the calculator.

~~~ROBO~~~

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 15-Apr-07 22:25   »» 
how would i make it so that you could type in your own problem and it would do it.

lets say i say:

45 * ((635 - (672 / 2)) + (7 * 7))

and it does the problem and gets the correct answer of 15,660.

would that be possible?

matt wuz here

dail8859

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 16-Apr-07 20:17   »» 
Wow, you seem to be getting the hang of programming and you seem to like it. That is good.

Matthew, for complex expressions like that it would be VERY hard, not impossible. There may be an easy way of doing it but i dont know any.

Ok, i am working on FLLG v2.0 It is the same as the 1.5 version but it has a GRAPHICAl USER INTERFACE. WOOOHOOOO. Like text boxes and buttons and labels and stuff. All in C. It is REALLY hard but possible. I hope to post it by the end of the week. I have got the User Interface all set up, i just need to figure out a few things like working with radio buttons.

cactus2

»» models

Re: Do you want to learn to program in C   posted: 16-Apr-07 21:35   »» 
You talking about the Windows API? Yeah, dialogs are harder to make than regular windows. But using a window is so much better than command line.

There is probably some efficient way to parse expressions, although I'm too lazy to figure one out.

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 16-Apr-07 23:23   »» 
what i was thinking of was somethting like this:

{
float answer;
char problem[30];
{
printf(your problem: ); // user inputs problem
scanf("%c", &problem);
}
answer = problem
{
printf("%f", answer);
}

or something like that. just get the point that i want to make it so...

answer = problem

that way if the problem was 2 * 2, it would be...

answer = 2 * 2

then it would get the correct answer of 4

if that gives you any ideas, please, go right ahead and make it. i have no idea how i could, and if i did i would probably be too lazy to do it anyway.

matt wuz here



This topic has 357 replies on 24 pages [ « | 1 ... 10 11 12 13 14 15 16 17 18 ... 24  | » ]


»» previous topic   »» next topic  

»» back to topic list  »» top of the page  

PLEASE READ THE FORUM GUIDELINES AND ALWAYS PREVIEW TO CHECK MESSAGES BEFORE POSTING...
...Help keep our forums creative and constructive. Thank you.


»» forum home