![]() |
New program..need help with random
I need to make a program that contains 9 flashcards (question at one side and its answer overleaf). The program randomly selects between the 9 different flashcards then it prints any side of the flashcard (either the question or the answer side).
C Language |
Re: New program..need help with random
OK, it's not difficult. How far have you got and where are you stuck? Do you understand the assignment?
Have you worked out how to represent the flash cards? (for example would a simple array of strings be sufficient?) Do you know how to get a random number? How would you determine whether to display question or answer: is that also random? Having worked out how to represent the flash cards, can you think of a way to combine that with the answers to the last two questions? If the answer to all those is yes then you should have enough to start coding. |
Re: New program..need help with random
Here is the full description of the assignment:
Here is my starting random program: Code:
#include<stdio.h> |
Re: New program..need help with random
Seems pretty detailed. Where are you stuck? Or are you just hoping someone will write it for you?
|
Re: New program..need help with random
No! I'm stuck in the second random part, the random inside the random
|
Re: New program..need help with random
So if getNextNum() selects a card, then you need a second random number to select which side to show.
|
Re: New program..need help with random
Yup!:) what I am thinking is to make another function that has an array which has a size equal to two but the problem is the printing part for the sides
|
Re: New program..need help with random
There isn't any code that displays any part of the slides. Have a go at writing it and see where you get stuck. If you can't figure out how to display a random side, just display the same side each time and I'll see if I can fit a "rand()%2" in there somewhere.
I don't see how an array of size 2 helps though. Why would you need to store two numbers? |
Re: New program..need help with random
Sorry sir but I just made it complicated. Here is my problem now, how will I print the different passages without repeated because when I add a conditional statement inside the for loop the numbers are being repeated until all numbers are used.
Here is my updated code: Code:
#include<stdio.h> |
Re: New program..need help with random
Case blocks must be terminated with break otherwise it will continue to the next:
Code:
int x=1;I still don't see where you're deciding which side of the card to show (perhaps you haven't attempted to write that code yet). I also don't get what GetNextNum is trying to do; it seems unnecessarily complicated. A much simpler algorithm for GetNextNumber is to forget static variables and initialise the array in a separate routine which you call once at the start of main. Populate the array with numbers 0 to size-1 then for each entry in the array swap it with a randomly selected other entry in the array. When you want to display the card you decide which side to show; this doesn't need to be stored anywhere if I understand it correctly, so just pick a random number below 2, check if it's 0 or 1 and display the relevant side of the card. Or do you need to store the side random number, and if so why? |
| All times are GMT +5.5. The time now is 08:59. |