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 ... 19 20 21 22 23 24 | » ]
»» previous topic   »» next topic  


matthew102000

»» models

Re: Do you want to learn to program in C   posted: 08-Jul-07 16:38   »» 
how do you make it. the closest i could find was this...

„c

if thatt shows up as something other than a square

matt wuz here

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 08-Jul-07 16:41   »» 
oops i misread your post. but there is still an error in this line...

printf("What is your bet? You have %f credits", &winnings);

matt wuz here

cactus2

»» models

Re: Do you want to learn to program in C   posted: 08-Jul-07 17:27   »» 
That's because there is no variable names winnings. It's current winnings. It messes up because of the ampersand. It turns & currentwinnings into ¤ twinnings.
http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Character_entities_in_HTML

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 08-Jul-07 18:44   »» 
ok im a little confused. what symbol are we using? the star thingy, the & symbol ot the one armed sidways t thing.

matt wuz here and cant figure it out

cactus2

»» models

Re: Do you want to learn to program in C   posted: 08-Jul-07 20:57   »» 
Just rename currentwinnings winnings and then fix the code everytime it was used.

cactus2

»» models

Re: Do you want to learn to program in C   posted: 08-Jul-07 21:00   »» 
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main (void)
{
char response[10];
int n=0;
int n2=0;
int picknum=0;
int picks[20];
int randomnumbers[20];
int correct=0;
float bet=0;
float winnings=100;

srand(time(NULL)); //Seed the random nubmer generator
do{
n=0;
n2=0;
correct=0;
printf("How many numbers do you want to pick?");
scanf("%d", &picknum);
if(picknum>20) picknum=20;
if(picknum<1) picknum=1;
printf("What is your bet? You have %f credits", winnings);
scanf("%f", &bet);

while(n<picknum)
{
scanf("%d", picks+n);
if(picks[n]<80&&picks[n]>0) n++;
}
n=0;
while(n<20)
{
int test=rand()%80+1:
while(n2<n) //Check every value to make sure it isn't a duplicate
{
if(test==randomnumbers[n2]) break;
n2++;
}
if(n2==n)//If the while loop didn't break, they would be equal
{
randomnumbers[n]=test;
n++;
}
n2=0;
}
n=0;
n2=0;
while(n<picknum)
{
while(n2<20)
{
if(picks[n]==randomnumbers[n2]) correct++;
n2++;
}
n2=0;
n++;
}

//Don't know the scoring formula. Paste it here.
winnings+=((picknum*bet*correct)/10);
prinft("You had %i correct. Your current number of credits is %f. Continue?(Y/N)", correct, winnings);
scanf("%s", response);
if(response[0]=='N' || response[0]='n') break;
}while(winnings>0);
printf("You have won %i credits", winnings);
}

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 08-Jul-07 21:24   »» 
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main (void)
{
char response[10];
int n=0;
int n2=0;
int picknum=0;
int picks[20];
int randomnumbers[20];
int correct=0;
float bet=0;
float winnings=100;

srand(time(NULL)); //Seed the random nubmer generator
do{
n=0;
n2=0;
correct=0;
printf("How many numbers do you want to pick?");
scanf("%d", &picknum);
if(picknum>20) picknum=20;
if(picknum<1) picknum=1;
printf("What is your bet? You have %f credits", winnings);
scanf("%f", &bet);

while(n<picknum)
{
scanf("%d", picks+n);
if(picks[n]<80&&picks[n]>0) n++;
}
n=0;
while(n<20)
{
int test=rand()%80+1;
while(n2<n) //Check every value to make sure it isn't a duplicate
{
if(test==randomnumbers[n2]) break;
n2++;
}
if(n2==n)//If the while loop didn't break, they would be equal
{
randomnumbers[n]=test;
n++;
}
n2=0;
}
n=0;
n2=0;
while(n<picknum)
{
while(n2<20)
{
if(picks[n]==randomnumbers[n2]) correct++;
n2++;
}
n2=0;
n++;
}

//Don't know the scoring formula. Paste it here.
winnings+=((picknum*bet*correct)/10);
printf("You had %i correct. Your current number of credits is %f. Continue?(Y/N)", correct, winnings);
scanf("%s", response);
if(response[0],.=='N' || response[0]='n') break;
}while(winnings>0);
printf("You have won %i credits", winnings);
}

i fixed some probs but thee is a prob with the last couple of lines. mainly the 66th line

mayy wuz here

cactus2

»» models

Re: Do you want to learn to program in C   posted: 09-Jul-07 14:16   »» 
You put an extra ., on line 66. That causes a syntax error. What are the other problems?

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 09-Jul-07 16:59   »» 
still a prob in line 66.

expected primary-expression before '==' token

if(response,=='N' || response[0]='n') break;

matt wuz here

cactus2

»» models

Re: Do you want to learn to program in C   posted: 09-Jul-07 20:44   »» 
Line 66 is supposed to read
if(response[0]=='N' || response[0]=='n') break;

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 09-Jul-07 21:06   »» 
the program works, but when its time to enter the credits, the program dosent except it. it dosent ask you the next question.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main (void)
{
char response[10];
int n=0;
int n2=0;
int picknum=0;
int picks[20];
int randomnumbers[20];
int correct=0;
float bet=0;
float winnings=100;

srand(time(NULL)); //Seed the random nubmer generator
do{
n=0;
n2=0;
correct=0;
printf("How many numbers do you want to pick?");
scanf("%d", &picknum);
if(picknum>20) picknum=20;
if(picknum<1) picknum=1;
printf("What is your bet? You have %f credits", winnings);
scanf("%f", &bet);

while(n<picknum)
{
scanf("%d", picks+n);
if(picks[n]<80&&picks[n]>0) n++;
}
n=0;
while(n<20)
{
int test=rand()%80+1;
while(n2<n) //Check every value to make sure it isn't a duplicate
{
if(test==randomnumbers[n2]) break;
n2++;
}
if(n2==n)//If the while loop didn't break, they would be equal
{
randomnumbers[n]=test;
n++;
}
n2=0;
}
n=0;
n2=0;
while(n<picknum)
{
while(n2<20)
{
if(picks[n]==randomnumbers[n2]) correct++;
n2++;
}
n2=0;
n++;
}

//Don't know the scoring formula. Paste it here.
winnings+=((picknum*bet*correct)/10);
printf("You had %i correct. Your current number of credits is %f. Continue?(Y/N)", correct, winnings);
scanf("%s", response);
if(response[0]=='N' || response[0]=='n') break;
}while(winnings>0);
printf("You have won %i credits", winnings);
}

matt wuz here

cactus2

»» models

Re: Do you want to learn to program in C   posted: 09-Jul-07 21:14   »» 
That's because I didn't program that in.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main (void)
{
char response[10];
int n=0;
int n2=0;
int picknum=0;
int picks[20];
int randomnumbers[20];
int correct=0;
float bet=0;
float winnings=100;

srand(time(NULL)); //Seed the random nubmer generator
do{
n=0;
n2=0;
correct=0;
printf("How many numbers do you want to pick?");
scanf("%d", &picknum);
if(picknum>20) picknum=20;
if(picknum<1) picknum=1;
do{
printf("What is your bet? You have %f credits", winnings);
scanf("%f", &bet);
}while(bets>winnings);
while(n<picknum)
{
if(n==0) printf("Enter your first pick.");
else printf("Enter your next pick.");
scanf("%d", picks+n);
if(picks[n]<80&&picks[n]>0) n++;
}
n=0;
while(n<20)
{
int test=rand()%80+1;
while(n2<n) //Check every value to make sure it isn't a duplicate
{
if(test==randomnumbers[n2]) break;
n2++;
}
if(n2==n)//If the while loop didn't break, they would be equal
{
randomnumbers[n]=test;
n++;
}
n2=0;
}
n=0;
n2=0;
while(n<picknum)
{
while(n2<20)
{
if(picks[n]==randomnumbers[n2]) correct++;
n2++;
}
n2=0;
n++;
}

//Don't know the scoring formula. Paste it here.
winnings+=((picknum*bet*correct)/10);
printf("You had %i correct. Your current number of credits is %f. Continue?(Y/N)", correct, winnings);
scanf("%s", response);
if(response[0]=='N' || response[0]=='n') break;
}while(winnings>0);
printf("You have won %i credits", winnings);
}

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 09-Jul-07 21:22   »» 
never mind figured it out. you never told anybody to start entering the numbers. one prob thogh. you need to be able to loose credits somehow. i bet all 110 of my credits, and got zero right. i still had all of my credits. and we also need to make it so that you can only win credits if you get lets say 5 or more right, if possible.

matt wuz here

matthew102000

»» models

Re: Do you want to learn to program in C   posted: 09-Jul-07 21:40   »» 
i was playing the game a little more. remember my formula for winnings. well i found a glitch that has to do with the bet, numbers to pick, and my formula. ya see, you can enter up to 99 for amoun of numbers to pick, and you can bet more than you have, and since you cant lose credits, the program enters thos numbers into the formula. then you type 20 random numbers (aka 1-20), and watch your credits gro exponantoly. we need a way to make sure this dosent happen. also, i revised the printf statments a little mor to make it look and feel better.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main (void)
{
char response[10];
int n=0;
int n2=0;
int picknum=0;
int picks[20];
int randomnumbers[20];
int correct=0;
float bet=0;
float winnings=100;

srand(time(NULL)); //Seed the random nubmer generator
do{
n=0;
n2=0;
correct=0;
printf("How many numbers do you want to pick?\n \n \t - ");
scanf("%d", &picknum);
if(picknum>20) picknum=20;
if(picknum<1) picknum=1;
printf("What is your bet? You have %f credits\n \n \t - ", winnings);
scanf("%f", &bet);
printf("enter the #'s (1-80) you want to pick. type your #, then press enter.\n repeat as nessissary.\n \n");

while(n<picknum)
{
scanf("%d", picks+n);
if(picks[n]<80&&picks[n]>0) n++;
}
n=0;
while(n<20)
{
int test=rand()%80+1;
while(n2<n) //Check every value to make sure it isn't a duplicate
{
if(test==randomnumbers[n2]) break;
n2++;
}
if(n2==n)//If the while loop didn't break, they would be equal
{
randomnumbers[n]=test;
n++;
}
n2=0;
}
n=0;
n2=0;
while(n<picknum)
{
while(n2<20)
{
if(picks[n]==randomnumbers[n2]) correct++;
n2++;
}
n2=0;
n++;
}

//Don't know the scoring formula. Paste it here.
winnings+=((picknum*bet*correct)/10);
printf("You had %i correct. Your current number of credits is %f.\n \nContinue?(Y/N)\n \n \t - ", correct, winnings);
scanf("%s", response);
if(response[0]=='N' || response[0]=='n') break;
}while(winnings>0);
printf("You have won %i credits\n \n", winnings);
}


matt wuz here

cactus2

»» models

Re: Do you want to learn to program in C   posted: 09-Jul-07 22:52   »» 
Actually, there was a mechanism to avoid that.
if(picknum>20) picknum=20;
if(picknum<1) picknum=1;
do{
printf("What is your bet? You have %f credits", winnings);
scanf("%f", &bet);
}while(bets>winnings||bets<0);
The top one makes sure that it is between 1 and 20, and the second part makes sure the program won't continue until the bet is within hte bounds.



This topic has 357 replies on 24 pages [ « | 1 ... 19 20 21 22 23 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