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


dail8859

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 29-Mar-07 18:19   »» 
Matthew. You put int answer = z; Why, answer is an int and can only hold numbers not letters. Same wit the floats, the cant hold letters, and you have too many { and }. the way you would do the program is like this

#include <stdio.h>
int main (void)
{
float answer;
float number1, number2;
char function;

printf("CALCULATOR\n");
printf("------------------------------\n \n");
printf("First number\n \n \t - ");
scanf("%f", &number1);
printf("\n function, (e.g. +, -, /, *)\n \n \t - ");
scanf("%c", &function);
printf("Second Number\n \n \t - ");
scanf("%f", &number2);

if (function == '+')
{
answer = number1 + number2;
}

if (function == '-')
{
answer = number1 - number2;
}

if (function == '*')
{
answer = number1 * number2;
}

if (function == '/')
{
answer = number1 / number2;
}

printf("%d", answer);

scanf("%c");
return 0;
}


answer should be a float because you might * or / two floats. You were trying to rename a varible i think. You cannot to that. I think this will work. Look over it good and see the changes i made and why.


Now, Part 2 is coming along. So far 16 pages and 6000+ words. It has 15+ examples included in the zip folder.

dail8859

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 29-Mar-07 18:21   »» 
STDP

the last printf should be

printf("%f", answer);

so it can print out a float.

And by the way, you had the idea behind it, not just the syntax. Keep it up and youll do fine.

mmaarrkkuuss

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 29-Mar-07 20:09   »» 
I can't make this work. (Not surprising:P)

#include<stdio.h>

int main(void)

{
char name[20];
float number;
float count;
FILE *fp;

count = 0;

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

printf("How high should I count?");
scanf("%f", &number);

do
{
printf("Please enter a number greater than 0");
scanf("%f", &number);
} while (number>=1);

fp=fopen(name, "w");

while ( count <= number)
{
printf("%f", &count);
count++;
}

fclose(fp);

printf("File successfully created");

scanf("%c");

return 0;
}

I would be glad if someone would help:)

~mmaarrkkuuss~

ROBO_HEN5000

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 29-Mar-07 22:15   »» 
Pretty easy mistake, the argument in the 23rd line, "while (number >= 1)" is wrong. This makes say "Enter a number other than 0" whenever the number is GREATER than or equal to, not less than. It's like this (delete the <<<<'s)

#include<stdio.h>

int main(void)

{
char name[20];
float number;
float count;
FILE *fp;

count = 0;

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

printf("How high should I count?");
scanf("%f", &number);

do
{
printf("Please enter a number greater than 0");
scanf("%f", &number);
} while (number<=1);<<<<<<<<<<<<<<<<<<<<<<<<<<<

fp=fopen(name, "w");

while ( count <= number)
{
printf("%f", &count);
count++;
}

fclose(fp);

printf("File successfully created");

scanf("%c");

return 0;
}

I hope that is what you wanted.

~~~ROBO~~~

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 29-Mar-07 23:10   »» 
i made this one. its pretty cool. i was experimenting with dails counting machine. im posting it just to give you ideas.

matt wuz here

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 30-Mar-07 01:15   »» 
i cant post it. sorry!

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 30-Mar-07 01:36   »» 
i cant find the problem.

#include <stdio.h>
int main (void)
{
int diamiter;
float circumfrence;

{
printf("CIRCLE CIRCUMFRENCE FINDER\n");
printf("------------------------------------\n \n");
printf("What is the diamiter of the circle?\n \n \t - ");
scanf("%f", &circumfrence);
}
do
{
(circumfrence == diamiter * 3.14);
}
while
{
(diamiter > 0);
}
{
printf("%f", circumfrence);
}

scanf("%c");
return 0;
}

it finds the circumfrence of a circle by multiplying the diamiter and pi (3.14 [estimation]). how can i fix it.

it sucks because whenever i make a program, i cant find one little error thats messing it up so i always end up having to post it.

matt wuz here

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 30-Mar-07 02:14   »» 
aww great, now its really screwed...

#include <stdio.h>
int main (void)
{
int diamiter;
float circumfrence;

{
printf("CIRCLE CIRCUMFRENCE FINDER\n");
printf("------------------------------------\n \n");
printf("What is the diamiter of the circle?\n \n \t - ");
scanf("%d", &diamiter);
}
do
{
(circumfrence == diamiter * 3.14);
}
while(diamiter > 0);
{
printf("%f", circumfrence);
}

scanf("%c");
return 0;
}

matt wuz here

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 30-Mar-07 22:36   »» 
*bump*

matt wuz here

ROBO_HEN5000

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 31-Mar-07 19:07   »» 
Man, your program was seriously skrewd up.

#include <stdio.h>
#include <math.h>//comment 1
int main (void)
{
int diameter;// 2
float circumference;// 3

printf("CIRCLE CIRCUMFERENCE FINDER\n");// 3
printf("------------------------------------\n \n");
printf("What is the diameter of the circle?\n \n \t - "); //2
scanf("%i", &diameter);
circumference = diameter * 3.14;// 4
printf("%f", circumference);// 5
scanf("%z");// 6
}

Ok, Here are the comments for future reference:
1. You have to include the file math.h for math functions to work, like multiplication.
2. You spelled diameter wrong.
3. You spelled circumference wrong.
4. You had this in a "while" loop. This keeps setting circumference to diameter*3.14 forever, so you never even get to printf.
5. You also had this in a "while" loop. That keeps printing circumference forever, as long as diameter is positive.
6. I don't know about you guys, but "%c" always gives me an error message. I know it's supposed to be ok, but I t doesn't work on my pc.

Well, I hope that helped! Keep in mind that my problem with the pi formula was never solved, if anyone can please figure it out. Thanks!!!!

~~~{ROBO} > [31337]~~~

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 31-Mar-07 20:17   »» 
thanks. i am a bad speller.

matt wuz here

cactus2

»» models

Re: Do you want to learn to program in C   posted: 31-Mar-07 20:46   »» 
>No one has answered my pi

>No clue. Probably some accuracy problem.

I'll go post a pi calculator tomorrow.

dail8859

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 01-Apr-07 19:23   »» 
Ok, ive got alot of info stuffed into the next part. I am not done yet, i am about 85% done though.

Matthew, i always notice that you put alot of { and } in places you do not need them. You only need them for the main, loops and if/else. You do not need them around printf statements.

I looked into calculating pi once. It was hard, i do know of some people at my college that calculated pi the the one millionth digit, but i am not for sure how they did it. I think the computer took a little over an hour to get the one millionth digit.

ROBO_HEN5000

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 01-Apr-07 20:05   »» 
I think that your friends, if it took them like an hour, used a re-iterative formula that converged rather slowly. I am using something that converges rather quickly, but is relatively (RELATIVELY!!) simple. I was hoping to find a more complicated one that converges even faster, like maybe the nonic conversion of the same algorithm:

http://en.wikipedia.org/wiki/Borwein%27s_algorithm#Nonic_convergence

I don't know if anyone here has any hardcore C++ experience, but if you do, I could use some advice.

~~~ROBO~~~

cactus2

»» models

Re: Do you want to learn to program in C   posted: 01-Apr-07 21:40   »» 
I have a feeling that the nonic convergence will have the same glitch as the original one.



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