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


matthew102000

»» models

Re: Do you want to learn to program in C   posted: 08-Apr-07 17:43   »» 
still...

line 17: Parse Error, expecting `'}''
'else { printf("What is the radius of the circle???\n \n \t - ")'


matt wuz here

cactus2

»» models

Re: Do you want to learn to program in C   posted: 08-Apr-07 19:04   »» 
Found it. Extra semicolon.

#include <stdio.h>
#include <math.h>
int main (void)
{
float diameter, area, radius, circumference, choice;
printf("CIRCLE CIRCUMFERENCE/AREA FINDER\n");
printf("------------------------------------\n \n");
printf("Area or Circumference??? 1=cricumference, 2= 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 \t- %f", circumference);
}
else
{
printf("What is the radius of the circle???\n \n \t - ");
scanf("%f", &radius);
area = (radius * radius) * 3.14;
printf("\n \n \t \t = %f", area);
}
scanf("%c");
return 0;
}

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 08-Apr-07 19:38   »» 
thanks. im adding the calculater that i made (with some help from you guys) to it. not there is some bug saying:

" expecting `'}'' "

but it doesnt say where.

please help.

thanks!

matt wuz here

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 08-Apr-07 19:43   »» 
oops! here it is...



#include <stdio.h>
#include <math.h>
int main (void)
{
float diameter, area, radius, circumference, choice, number1, number2, answer;
char function;
printf("MATH HOMEWORK HELPER\n");
printf("------------------------------------\n \n");
printf("Area, Circumference, or Calculater???\n \n 1 = cricumference\n 2 = area\n 3 = calculater\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)3)
{
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("%f", &answer);
}
scanf("%c");
return 0;
}



matt wuz here

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 08-Apr-07 20:20   »» 
http://www.myfilelink.co.uk/file.aspx?id=be4987b9d76b4da69f08aba1a524717c

here is what i have so far. savefile.com doesnt work for me. not with downloading, or uploading anymore.

dail, can you post the thing on http://www.myfilelink.co.uk/

matt wuz here

cactus2

»» models

Re: Do you want to learn to program in C   posted: 08-Apr-07 22:47   »» 
#include <stdio.h>
#include <math.h>
int main (void)
{
float diameter, area, radius, circumference, choice, number1, number2, answer;
char function;
printf("MATH HOMEWORK HELPER\n");
printf("------------------------------------\n \n");
printf("Area, Circumference, or Calculater???\n \n 1 = cricumference\n 2 = area\n 3 = calculater\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)3)
{
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("%f", &answer);
}
scanf("%c");
return 0;
}

dail8859

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 09-Apr-07 20:26   »» 
WOW!!!! 28 downloads!!!

Anyways, im glad to see people getting concept of programming in C. Especially yours matthew. You dont give up, and that is important. It can get frustrating at times. When you compare 'choice' to 1 or 2 or 3 since it is a float, try comparing it to 1.0 or 2.0 or 3.0. Or change choice to an int. But whatever works.

Here is a link to myfilelink, i cant download from it but i can upload. Let me know if this works matthew
http://www.myfilelink.co.uk/file.aspx?id=300beff05bef4687a3d676f124fed22c


I have a request to all the people in here. If anybody has made a soda generator, even if it is simple, i want to make a giant soda generator that does almost anything. I will include what i have done in the Flex Line and Loop Generator. If any body else would like to contribute, email me your source file or if you have to, post it. If you contribute....
1) Make sure it works!!!

2) You can keep it as a main() function, i will change main() to make it be called as a function.

3) Include your name and anything at the top of the source file.

It will be released as an open source program. So you can download all the source for it and the executeable. If there are any suggestions let me know.

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 10-Apr-07 23:21   »» 
thanks dail!!! it worked. wow. just wow. thats long. how did you ever manage to type all that. i groan when i have to type 1 page for school.

and thanks to you to cactus. ill check to see if it works now. i think the calculater is probabbly the best, because, you can find the area of a circle, instead of typing in your radius and it does it for you. hope that makes sence.

thanks again dail. im printing it out now. it gonna take a while.

matt wuz here

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 11-Apr-07 00:30   »» 
one more thing. the calculater wont show the answer. whatever you do you get 0.000000. please help.

matt wuz here

dail8859

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 11-Apr-07 20:38   »» 
I managed to type it because I thought it was, dare i say, fun. What can i say, i like programming.

About your calculator, dont put the & for printf(). It was so simple but took me a little while to find it. I did have a problem where it would skip the scanf() function for the -,+ or whatever. If this ever happends that it skips one of your scanf() functions, make it do the scanf() function 2 times like

scanf("%c", &function);
scanf("%c", &function);

or you can type

fflush(stdin);

before the scanf() that is messing up. The reason it skips scanf() sometimes is because there is still stuff on the DOS console that it reads in. The fflush() clears everything waiting to be scaned in. It may just do this in Dev-C++ though.

And to check to see if the program should divide the two numbers, it should be

if (function == '/')

with just one /

For one of your first programs, you have done very well. Keep it up

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 11-Apr-07 23:22   »» 
forget the calculater. thats too complicated. now i have a square/cube area finder. the only problem is that it still wont show the answer for the cube or square. iv added it to my circle thingy. here it is. its at the end.


#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 \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)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;
}


thanks. if you guys want me to, i will ad the calculater. or i can make it so that it will do the things by a choice of what you want. tha calculater is made for basic math, and your probably better off using your own, considering this will take so long. but if you guys want i will.

and is there a way i can make the thing do algebra???

thanks!

matt wuz here

cactus2

»» models

Re: Do you want to learn to program in C   posted: 11-Apr-07 23:45   »» 
#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 \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)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;
}

Not sure if that would fix it, although it should help.

It'd be really complex, although possible, to make one that does algebra. You'd have to parse through user input to find all the coeffiecients, variables, and stuff.

Below is a pi calculator. I doubt it will have a high precision.
//Continued fraction algorithm for pi computation.
//http://en.wikipedia.org/wiki/Continued_fractions#Continued_fraction_expansions_of_.CF.80
#include <stdio.h>
#include <math.h>

void main()
{
double pi=3;
double term=1;
int n=0;
printf("Accuracy? ")
scanf("%i", &n);
while(n>2) //This produces all the parts except for the final one.
{
term=((n^2)/term)+6;
n--;
}
pi=3+1/term;
}

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 12-Apr-07 00:56   »» 
nope. it still has the same dumb problem. any other way to fix it. this stupid program should know what to do. i made it as easy as possible. oh well.

matt wuz here

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 12-Apr-07 01:08   »» 
sorry for adding so mutch so fast, but now ive added a square circumference finder that wont work. when you input the 4 to choose it nothing shows up, even thogh i have stuff typed in there. what is wrong with it?

#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)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);
}
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);
}
}
scanf("%f");
return 0;
}

like i said, sory for adding so mutch so fast, but i cant find the problem. and please try to find the bug in the area thing to.

Thanks!!!

matt wuz here

dail8859

»» models
»» homepage

Re: Do you want to learn to program in C   posted: 12-Apr-07 13:19   »» 
You DO NOT NEED THE & in the last printf() statement. This was the problem last time and it is still there. Make sure you have all of your curly braces correct. I dont have enough time right now to look into it to much.



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