The function definition of "correct()" goes after and outside of "main()".
[edit] Rather than retype it, see post #4 here: need help calling a function, please.
The function definition of "correct()" goes after and outside of "main()".
[edit] Rather than retype it, see post #4 here: need help calling a function, please.
I figured this all out... thanks...but I was just wondering, how would I get the real answer of for example a=78/10 then?!
I mean I know since a is an int, then it just gives us 7...but I changed the int to float (or double), and it gave me the result of the fraction(78/10) 7.00000!!!!!! which is obviously not!!!
(if someone going to to the favor and explain that to me, please explain what's the difference between double and float!!!!!! I just seem to understand you guys language better than my book( C by Discovery!!!, it sucks!) )
Code:int main() { float a,b; a=76; b= 76/10; printf("%f",b); return 0; }
Yes, though it does have the weakness of introducing a slight bias in most cases.Originally Posted by Ashl7
Yes, though you probably wanted (rand() % 90) + 10 unless you want to exclude 99.Originally Posted by Ashl7
You probably did not print the result correctly.Originally Posted by Ashl7
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Yes, because contrary to your claim that you "changed the int to float (or double)", you didn't: 76/10Originally Posted by Ashl7
You probably intended to write: 76.0f / 10.0f
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
ok, with the help of you guys and this website...I finally managed to write this damn code...all the answers I got lead to this...so thank you so much
this was the question:
Suppose you want to develop a program to play lottery. The program randomly generates a Lottery of a two-digit number, prompts the user to enter a two-digit number, and determines whether the user wins according to the following rule:
1. If the user matches the lottery in exact order , the awards is $10,000.
2. If the user input matches the lottery, the awards is $3,000.
3. If one digit in the user input matches a digit in the lottery, the awards is $1,000.
this is the code I wrote:
thanks thanks thanks...more questions to comeCode:#include <stdio.h> #include <stdlib.h> int main() { srand(time(NULL)); int lott,guess,ldiglot,rdiglot,ldigguess,rdigguess; lott=(rand() % 90) + 10; printf("what's your guess for the lottary number?! It's a TWO digit number...\n"); scanf("%d",&guess); rdiglot=lott % 10; ldiglot= lott/10; rdigguess= guess %10; ldigguess= guess/10; if(guess==lott) printf("WoW, you've won $10,000\n"); else if( rdiglot==ldigguess && ldiglot==rdigguess) printf("hmmmm, close...you won $3000"); else if(rdiglot==rdigguess || rdiglot==ldigguess || ldiglot==ldigguess || ldiglot==rdigguess ) printf("not the right answer,but you won $1000"); else printf("wrong answer"); return 0; }
however I'm still struggling with the question I asked at the beginning of the thread...
Last edited by Salem; 10-13-2012 at 05:21 AM. Reason: snipped opinion
You mean like
Code:switch ( rand() % 4 ) { case 0: // is it obvious yet? }
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
well the thing is, that piece of program should be able to get a number, and if that number is the one we want, then it say:
"Very good!", "Excellent!",
"Nice Work!",
"Keep up the good work!"
one of the above, randomly...we have to use rand() function here with the help of switch!!!!!! :/
the one u gave wasn't really obvious( to me, a retarded guy ) to be honest
Print something.
Then case 1 and print something else.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
alright...with the help of u guys, I wrote this program for the question at the beginning of the thread:
now a few questions:Code:#include <stdio.h> #include <stdlib.h> #include <time.h> void func(void) { srand(time(NULL)); int a,b,c; a= rand() % 10; b= (rand() % 10); printf("How much is the product of %d and %d? \n",a,b); scanf("%d",&c); } void wrong ( void ) { const char *responses[] = { "No. Please try again.", "Wrong. Try once more.", "Nope,Don’t give up!", "No...Keep trying." }; printf("%s\n", responses[rand()%4] ); } void correct( void ) { const char *responses[] = { "Very good!", "Excellent!", "Nice Work!", "Keep up the good work!" }; printf("%s\n", responses[rand()%4] ); } int main() { int a,b,c,d; printf("Hello, this is computer assited instruction for multiplication...\n"); func(); d=a*b; if(c==d) correct(); else wrong(); return 0; }
my program fails the part of the exercise that says "A separate function should be used to generate each new question. This function should be called once when the application begins execution and each time the user answers the question correctly"...I'm trying to make the func() in my codes the function we want, but the answer is going to be always wrong!!! even when I enter the write answer it says you put the wrong answer....what am I doing wrong here?!
the other part I have problem with is "and let the student try the same question repeatedly until the student finally gets it right." how am suppose to make a piece of code to enable this in my program?!
thanks in advance
The 'c' in func and 'c' in main are two different variables.
Try something in main like
c = func();
And make func() return a result.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I can't quite understand that, could u pls explain more?!
I guess that way the function will not be the one the assignment needs it to be!!