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 ... 9 10 11 12 13 14 15 16 17 ... 24  | » ]
»» previous topic   »» next topic  


cactus2

»» models

Re: Do you want to learn to program in C   posted: 12-Apr-07 21:39   »» 
#include <stdio.h>
#include <math.h>
int main (void)
{
float diameter, area, radius, circumference, choice, number1, number2, number3, answer, choice2;
char function;
printf("MATH HOMEWORK HELPER\n");
printf("------------------------------------\n \n");
printf("Area, Circumference, or Calculater???\n \n 1 = cricumference\n 2 = area\n 3 = square/cube area\n 4 = square circumference\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 \t circumference = %f", 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 \n \t area = %f", area);
}
if (choice == (float)4)
{
printf("what is the width of the square???\n \n \t - ");
scanf("%f", &number1);
printf("what is the height of the square???\n \n \t - ");
scanf("%f", &number2);
answer = (number1 * 2) + (number2 * 2);
printf("%f", &answer);
}
if (choice == (float)3)
{
printf("width of square\n \n \t - ");
scanf("%f", &number1);
printf("height of square\n \n \t - ");
scanf("%f", &number2);
printf("is the figure a cube? 1 = yes, 2 = no\n \n \t - ");
scanf("%f", &choice2);
if (choice2 == (float)1)
{
printf("length of cube\n \n \t - ");
scanf("%f", &number3);
answer = number1 * number2 * number3;
printf("%f", &answer);
}
if (choice2 == (float)2)
{
answer = number1 * number2;
printf("%f", &answer);
}
}
scanf("%f");
return 0;
}

ROBO_HEN5000

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 13-Apr-07 23:16   »» 
Here, I did a few things:

#include <stdio.h>
#include <math.h>
int main (void)
{
float diameter, area, radius, circumference, choice, number1, number2, number3, answer, choice2;
char function;
printf("MATH HOMEWORK HELPER\n");
printf("------------------------------------\n \n");
printf("Area, Circumference, or Calculater???\n \n 1 = Cricumference of a Circle\n 2 = Area of a Circle\n 3 = Area of a Rectangle or Rectangular Prism\n 4 = Perimeter of a Rectangle\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 cm\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 \n \t Area = %f cm^2\n", area);
}
if (choice == (float)3)
{
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\n", &answer);
}
if (choice2 == (float)2)
{
answer = number1 * number2;
printf("\n \n \t Area = %f\n", &answer);
}
}
if (choice == (float)4)
{
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\n", &answer);
};
system("PAUSE");
return 0;
}

First of all, I used the "system("PAUSE")" that was in Basics of C part 2. Also, I revised some of the input-output phrases to sound better. Still, choices 3 and 4 always output 0. Couldn't find the problem, some logic issue, probably. Hope that helped, and I think that we should make this a group project and expand it into one giant super-calculator! But only if that's ok with you, mmaarrkkuuss. Till next time,

~~~ROBO~~~

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 14-Apr-07 01:20   »» 
i think that thit is a great idea. iv been working on it lately, but i cant find ther error either. thanks for the great idea. iv been thinking that myself lately, but i couldnt post it yesterday because i was grounded from the computer, and my dad is only letting me check this today. ill be on tomarrow for sure.

tharks for editing it robo, it looks good.

like i said, making this a group prodject is a great idea. hope you guys like it two.

matt wuz here

mmaarrkkuuss

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 14-Apr-07 09:46   »» 
I still have a problem with generators. Here's the generator I've been working on:

#include<stdio.h>

int main (void)

{
float distance;
int masses, count;
char name[15];
FILE *fp;

printf("Name of new file: ");
scanf("%s", name);

fp = fopen( name, "w");

do
{
printf("Number of masses: ");
scanf("%d", &masses);
} while ( masses <=1);

do
{
printf("Distance between masses: ");
scanf("%f", &distance);
} while ( distance <= 10);

fprintf( fp, <"?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?">
<"!DOCTYPE sodaconstructor (View Source for full doctype...)">
"<model>\n"
"\t<comment></comment>\n"
"\t<container width=\"651\" height=\"422\" />\n"
"\t<environment gravity=\"0.25469473\" friction=\"0.042274434\" springyness=\"0.3537427\" />\n"
"\t<collisions surface_friction=\"0.1\" surface_reflection=\"-0.75\" />\n"
"\t<wave amplitude=\"0.76744187\" phase=\"0.67803925\" speed=\"0.014117647\" />\n"
"\t<settings gravitydirection=\"down\" wavedirection=\"reverse\" autoreverse=\"on\" />\n"
"<nodes>\n");



for ( count = 0; count < masses; count++)
{
fprintf( fp,"<mass id=\"m%d\" x=\"%f\" y=\"10.0\" vx=\"0.0\" vy=\"0.0\" />\n",count,current_loc);
}

fprintf( fp, "</nodes>\n");
fprintf( fp, "\t<links>\n");

for ( count = 0; count < masses-1; count++)
{

fprintf(fp,"<spring a=\"m%d\" b=\" m%d\" restlength=\"%f\" />\n",count, count+1,distance);
}

fputs("\t</links>\n", fp);
fputs("\t</model>\n", fp);

fclose(fp);

printf("File successfully created. ");

scanf("%c");

return 0;
}

It makes a .xml file and it looks exact the same as the other xml's, but when I try to import it to SClocal the constructor stops working. Even the drop-down menus and the wave is gone. Please help:)

mmaarrkkuuss

cactus2

»» models

Re: Do you want to learn to program in C   posted: 14-Apr-07 12:17   »» 
You forogt one mistake. there's a semicolon at the ned of an if statement.
#include <stdio.h>
#include <math.h>
int main (void)
{
float diameter, area, radius, circumference, choice, number1, number2, number3, answer, choice2;
char function;
printf("MATH HOMEWORK HELPER\n");
printf("------------------------------------\n \n");
printf("Area, Circumference, or Calculater???\n \n 1 = Cricumference of a Circle\n 2 = Area of a Circle\n 3 = Area of a Rectangle or Rectangular Prism\n 4 = Perimeter of a Rectangle\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 cm\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 \n \t Area = %f cm^2\n", area);
}
if (choice == (float)3)
{
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\n", &answer);
}
if (choice2 == (float)2)
{
answer = number1 * number2;
printf("\n \n \t Area = %f\n", &answer);
}
}
if (choice == (float)4)
{
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\n", &answer);
};
system("PAUSE");
return 0;
}


Mmaarrkkuuss, I have no clue what's wrong with your code.

mmaarrkkuuss

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 14-Apr-07 12:32   »» 
cactus, that's matt's code:|

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 14-Apr-07 14:35   »» 
the new and improved super calculater.

i got the rectangular prisim area and circomference working. i also made it look a little better by adding /n's and getting rid of them in some places.

#include <stdio.h>
#include <math.h>
int main (void)
{
float diameter, area, radius, circumference, choice, number1, number2, number3, answer, choice2;
char function;
printf("SUPER CALCULATER\n");
printf("------------------------------------\n \n");
printf("Area, Circumference, or Calculater???\n \n 1 = Cricumference of a Circle\n 2 = Area of a Circle\n 3 = Area of a Rectangle or Rectangular Prism\n 4 = Perimeter of a Rectangle\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 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^2\n \n", answer);
}
if (choice2 == (float)2)
{
answer = number1 * number2;
printf("\n \n \t Area = %f\n \n", answer);
}
}
if (choice == (float)4)
{
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^2\n \n", answer);
};
system("PAUSE");
return 0;
}


if you guys want to add your own functoins, go right ahead. like i said, i think it would be a great group prodject.

matt wuz here

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 14-Apr-07 14:37   »» 
and also, i found a glitch in the programming. when you exicute it, if you have a pc, try right clicking. the program should start doung the header ofer and over and over again. at least, it does that on my computer.

matt wuz here

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 14-Apr-07 14:48   »» 
oops!...

i forgot a couple of units^2 and changed the rectangular prism to units ^3. sorry i forgot about that. i should have thoughht about that five minutes ago when i posted the last one.

#include <stdio.h>
#include <math.h>
int main (void)
{
float diameter, area, radius, circumference, choice, number1, number2, number3, answer, choice2;
char function;
printf("SUPER CALCULATER\n");
printf("------------------------------------\n \n");
printf("Area, Circumference, or Calculater???\n \n 1 = Cricumference of a Circle\n 2 = Area of a Circle\n 3 = Area of a Rectangle or Rectangular Prism\n 4 = Perimeter of a Rectangle\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 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)4)
{
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^2\n \n", answer);
};
system("PAUSE");
return 0;
}

matt wuz here

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 14-Apr-07 15:10   »» 
fear of the quadruple post.

i fixed some spelling errors, and took away one of my units^2 errors. im smart!, you dont use that for perimeter!

#include <stdio.h>
#include <math.h>
int main (void)
{
float diameter, area, radius, circumference, choice, number1, number2, number3, answer, choice2;
char function;
printf("SUPER CALCULATOR\n");
printf("------------------------------------\n \n");
printf("1 = Cricumference of a Circle\n 2 = Area of a Circle\n 3 = Area of a Rectangle or Rectangular Prism\n 4 = Perimeter of a Rectangle\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 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)4)
{
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);
};
system("PAUSE");
return 0;
}

matt wuz here

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 14-Apr-07 18:41   »» 
new update:

#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 = Cricumference of a Circle\n 2 = Area of a Circle\n 3 = Area of a Rectangle or Rectangular Prism\n 4 = Perimeter of a Rectangle\n 5 = triangle area\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 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)4)
{
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)5)
{
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);
}
system("PAUSE");
return 0;
}

this has a triangle area finder.

matt wuz here

mmaarrkkuuss

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 14-Apr-07 19:55   »» 
matthew; please try not to post five times in a row even if they're constructive. Even if we usually ignore this rule we've got to follow it.

mmaarrkkuuss

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 14-Apr-07 20:24   »» 
sorry. i was just excited about the updates that i added, and seince there are not a lot of posts, nowbody posted inbetween. the bad part about this rule is people have to post if you want to post. if more people posted, then more people could post. get the point???

sorry!

matt wuz here

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 14-Apr-07 21:05   »» 
one quick question. does anybody know a good formula for finding the square root of a number?

matt wuz here

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 14-Apr-07 22:50   »» 
here is another update. no more for today from me.

#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 = Cricumference of a Circle\n 2 = Area of a Circle\n 3 = Area of a Rectangle or Rectangular Prism\n 4 = Perimeter of a Rectangle\n 5 = Cube Surface Area\n 6 = Triangle Area\n 7 = Pyramid Area\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 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)4)
{
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)5)
{
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)6)
{
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)7)
{
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);
}
system("PAUSE");
return 0;
}

this includes surface area of a cube and area of a pyramid. it also has area of a tryangle.

sorry for all the posts lately. nobody has been posting lately. normally people post more, and i, for some reason, am a little excited about this. sorry.

matt wuz here



This topic has 357 replies on 24 pages [ « | 1 ... 9 10 11 12 13 14 15 16 17 ... 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