I'm trying to code a simple adding program. How can I do this? Just asking questions (IE: "What's 1+1?" and gives the user a chance to input the number. Then bring up another question after the answer is correct.)
-Fool
I'm trying to code a simple adding program. How can I do this? Just asking questions (IE: "What's 1+1?" and gives the user a chance to input the number. Then bring up another question after the answer is correct.)
-Fool
Here's a sample program. Hope it helps.
Code:#include <cstdio> #include <cstdlib> #include <ctime> int main() { int n1, n2, answer; // Let's seed the random number generator with the current time // This is done to insure that every time the program is run, // it will have different questions. srand((unsigned)time(NULL)); // An infinite loop for(;;) { // First let's generate two random numbers between 1 and 10 n1 = rand() % 10 + 1; n2 = rand() % 10 + 1; // Ask the user for the answer and recieve it in the answer variable printf("What is %d + %d? (To quit type 0)\n", n1, n2); scanf("%d", &answer); // If the user typed 0, exit the loop and the program if(answer == 0) break; // Check for correct answer else if(answer == n1 + n2) printf("This is correct, %d + %d = %d!\n", n1, n2, answer); else printf("No, %d + %d = %d, not %d. Try again.\n", n1, n2, n1 + n2, answer); } return 0; }
- lmov
How did you get the syntax highlighting like that lmov? Did you write some code to add HTML to code to make it look so nice?
lmov,
Now that I've had a second to really look at it I understand it better. The only thing that throws me off is I wouldn't have known the commands. But the logic makes sence to me. Thanks again for the help.
SilentStrike,
I think he used a program like MSVC or DevC++ that will do that for you.
-Fool
It wont preserve the colours when transfering to code to the board. He went to Sunlight's site and downloaded the code formater.I think he used a program like MSVC or DevC++ that will do that for you.
You have to modify the source though, as the original was written for the Programers Heaven board.