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 ... 4 5 6 7 8 9 10 11 12 ... 24  | » ]
»» previous topic   »» next topic  


cactus1

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 25-Mar-07 12:41   »» 
STDP I menat "to keep" instead of "the keep"
Stupid absentmindedness...

mmaarrkkuuss

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 25-Mar-07 13:04   »» 
When I tried to replace the "w" with a "a" it did the same:( I can't make it work:P

~mmaarrkkuuss~

cactus1

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 25-Mar-07 16:23   »» 
Hmm..

#include<stdio.h>

int main (void)

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

current_loc=0;

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 < (float)10);

fprintf( fp, "<\?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"no\"\?> \n"
"<!DOCTYPE sodaconstructor>\n"
"<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);

current_loc = current_loc + distance;
}

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;
}

ROBO_HEN5000

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 25-Mar-07 18:20   »» 
sry to change the topic, but remember my post a couple of days ago? Saying that I was making a C++ Pi program from machin's variation? I CAN'T GET IT TO WORK!!!! I can get it compiled perfectly fine, but it always puts out 12.5664.
Also, I can't get it to put out a number longer than 6 places below the digits. Here it is:

#include <iostream.h>
#include <math.h>

int main(void)
{
long double pi;
cout << "Calculating Pi...\n";
pi = (16*atan(1))-(4*atan(1/239)); //Machin's variation
cout << "Pi = " << pi;
cin >> "mstdfs"; //Just to keep the window open
}

I know this is a topic for C not C++, but could someone help me?

~~~ROBO~~~

cactus1

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 25-Mar-07 18:40   »» 
The tigonometry function doesn't have enough accuracy. You're better off using this one, which takes advantage of the computer's recursiveness. http://en.wikipedia.org/wiki/Gauss-Legendre_algorithm

mmaarrkkuuss

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 25-Mar-07 19:09   »» 
It does not work:( Thanks for the help:) There is no bugs, but it does not work in sodaconstructor:) There must be something wrong with something else:P

cactus1

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 25-Mar-07 19:18   »» 
You sure you're opening it with the current thing? It should run in offline beta.

mmaarrkkuuss

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 25-Mar-07 19:46   »» 
That's where I import the XML file I've created with it.

~mmaarrkkuuss~ (sad:(.)

dail8859

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 25-Mar-07 23:52   »» 
Ok, i am finally back. I am on spring break and we only have dialup at home so im rarely on. Cactus, a big thanks for holding it all together while i wasnt able to post. And thanks to everybody else.

I will do a part 2, i have alot of ideas to cover, any ideas would be helpful

I am glad people are getting the hang of it

cactus1

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 26-Mar-07 00:42   »» 
You need to cover pointers, arrays, memory allocation, some compiler directives, casting, structures, the switch instruction, and making your own functions.

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 26-Mar-07 01:26   »» 
i doubt it, but is there way that i could make it so that a certain abount of words will be shown on one line, while people are typing? you know, like a preset amoun of words alloud on one line?

if there is, please reply.

matt wuz here

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 26-Mar-07 01:36   »» 
I cant get this to work rite. i cant find the bug, and i dont even know if it will work. please help.

#include <stdio.h>

int main (void)

{
char fname, type[5000];
FILE *fp;
{
printf("FILE GENERATOR\n");
printf("-----------------------------------------\n");
printf("Name of file\n \n \t - ");
scanf("%c", &fname);
}
{
printf("What do you want it to say?\n \n");
scanf("%c", type);
}
{
fp = fopen( fname, "w");
fprintf( fp,"%c", fname);
fclose;
}
}

scanf("%c");

return 0;

}

matt wuz here.

mmaarrkkuuss

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 26-Mar-07 12:57   »» 
#include <stdio.h>

int main (void)

{
char fname, type[5000];
FILE *fp;

printf("FILE GENERATOR\n");
printf("-----------------------------------------\n");
printf("Name of file\n \n \t - ");
scanf("%c", &fname);


printf("What do you want it to say?\n \n");
scanf("%c", type);


fp = fopen( fname, "w");
fprintf( fp,"%c", fname);
fclose;



scanf("%c");

return 0;

}

All your code should be in one "thing"

{All your code goes here. If you would like a loop, make the loop then after that Make another {loop code} } Remember to close the first one too.

Sorry if that did not make sense:P

~mmaarrkkuuss~

cactus1

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 26-Mar-07 22:35   »» 
Another small error. Your file has a max length of one and isn't properly addressed. You need it to be an array too. The closing function didn't have the file as its parameter.

#include <stdio.h>

int main (void)

{
char fname[50], type[5000];
FILE *fp;

printf("FILE GENERATOR\n");
printf("-----------------------------------------\n");
printf("Name of file\n \n \t - ");
scanf("%c", fname);


printf("What do you want it to say?\n \n");
scanf("%c", type);


fp = fopen( fname, "w");
fprintf( fp,"%c", type);
fclose(fp);



scanf("%c");

return 0;

}

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 26-Mar-07 22:48   »» 
it still dosent work rite. ill hit enter after i name the file, but it closes instead of asking what i want it to say. why???

matt wuz here



This topic has 357 replies on 24 pages [ « | 1 ... 4 5 6 7 8 9 10 11 12 ... 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