New program..need help with random

Discussion in 'C' started by askmewhy25, Mar 17, 2010.

  1. askmewhy25

    askmewhy25 New Member

    Joined:
    Jan 24, 2010
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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.
     
  3. askmewhy25

    askmewhy25 New Member

    Joined:
    Jan 24, 2010
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    0
    Here is the full description of the assignment:


    • The flashcards will be group into boxes A, B and C according to the flow as follows.

    1. From the selection screen, user chooses to start
    2. The program randomly shows a flashcard (either side, randomly) and the user guesses the other side (no input required)
    3. After guessing, the user selects to show the other side
    4. If correct, the user promotes the flashcard to box A. If incorrect, the user promotes the flashcard to box C. If the user is unsure or almost close to the correct one, the user promotes the flashcard to box B. The promotion is based on honest user input
    5. After the user goes through all the flashcards, the program gives the user's score and stores it with its corresponding date and time.
    6. From the selection screen, the user gets an option to redo the flashcards in box B and C as done in item 2 to 4
    7. The score gets recomputed and then displayed with previous score(s) after a single process in item 6 has been completed.

    • Boxes A, B and C are initially empty with the option that the user could empty them at the selection if they contain flashcards
    • Put a selection screen to show the stored scores and their corresponding date and time

    1. Score = number of flashcards in box A / total number of flashcards

    • A selection screen option for saving and loading the following:

    1. Scores (1 text file)
    2. Content of each box (3 text files)

    • The flashcards are biblical passages (reference at one side and passage content at the other)

    Here is my starting random program:
    Code:
    #include<stdio.h>  
    #include <conio.h>
    #include <math.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    
    int getNextNum(){
      static int list[9];
      static int size = -1;
      if (size==-1){
        size=9;
        for(int i=0;i<size;i++){ 
          list[i]=i+1;
          }
        }
      if(size==0){
        return 0;
        }
      int index=rand()%size;
      int num=list[index];
      size--;
      list[index] = list[size];
      return num;
    }
    
    
    int main(){
      const time_t timer=time(NULL);
      printf("%s\n",ctime(&timer));
      
      srand( time(NULL));
      int z;
      for(int i=0;i<9;i++){
        z=getNextNum();
        printf("Random Number: %d\n",z);
        }
      getche();
    }
    
     
    Last edited: Mar 18, 2010
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Seems pretty detailed. Where are you stuck? Or are you just hoping someone will write it for you?
     
  5. askmewhy25

    askmewhy25 New Member

    Joined:
    Jan 24, 2010
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    0
    No! I'm stuck in the second random part, the random inside the random
     
  6. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    So if getNextNum() selects a card, then you need a second random number to select which side to show.
     
  7. askmewhy25

    askmewhy25 New Member

    Joined:
    Jan 24, 2010
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    0
    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
     
    Last edited: Mar 18, 2010
  8. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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?
     
  9. askmewhy25

    askmewhy25 New Member

    Joined:
    Jan 24, 2010
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    0
    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>  
    #include <conio.h>
    #include <math.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    
    int getNextNum(){
      static int list[9];
      static int size=-1;
      if (size==-1){
        size=9;
        for(int i=0;i<size;i++){ 
          list[i]=i+1;
          }
        }
      if(size==0){
        return 0;
        }
      int index=rand()%size;
      int num=list[index];
      size--;
      list[index] = list[size];
      return num;
    }
    
    
    int main(){
      const time_t timer=time(NULL);
      printf("%s\n",ctime(&timer));
      
      srand( time(NULL));
      int z;
      for(int i=0;i<9;i++){
        z=getNextNum();
        switch(z){
          case 1:
            printf("Passage Number: %d\n",z);
            getche();
          case 2:
            printf("Passage Number: %d\n",z);
            getche();
          case 3:
            printf("Passage Number: %d\n",z);
            getche();
          case 4:
            printf("Passage Number: %d\n",z);
            getche();
          case 5:
            printf("Passage Number: %d\n",z);
            getche();
          case 6:
            printf("Passage Number: %d\n",z);
            getche();
          case 7:
            printf("Passage Number: %d\n",z);
            getche();
          case 8:
            printf("Passage Number: %d\n",z);
            getche();
          case 9:
            printf("Passage Number: %d\n",z);
            getche();
          }
        }
      getche();
    }
    
    
     
  10. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Case blocks must be terminated with break otherwise it will continue to the next:
    Code:
    int x=1;
    switch(x)
    {
    case 1: printf("x is 1\n");
    case 2: printf("x is 2\n");
    }
    
    will print both x is 1 *and* x is 2.

    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?
     
  11. askmewhy25

    askmewhy25 New Member

    Joined:
    Jan 24, 2010
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    0
    This is the shortest way that I know to make a random without repeating, the purpose of the GetNextNumber is for the flashcard but I replaced it with a new name with Card which represents the flashcards and the Side is for the sides of the flashcard. Now the problem is the repeating of the Side because it only prints for two flashcards after that it does not work anymore

    Here is my updated code:

    Code:
    #include<stdio.h>  
    #include <conio.h>
    #include <math.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    
    int Card(){
      static int list[9];
      static int size=-1;
      if(size==-1){
        size=9;
        for(int i=0;i<size;i++){ 
          list[i]=i+1;
          }
        }
      if(size==0){
        return 0;
        }
      int index=rand()%size;
      int num=list[index];
      size--;
      list[index] = list[size];
      return num;
    }
    
    int Side(){
      static int list[2];
      static int size=-1;
      if(size==-1){
        size=2;
        for(int i=0;i<size;i++){ 
          list[i]=i+1;
          }
        }
      if(size==0){
        return 0;
        }
      int index=rand()%size;
      int num=list[index];
      size--;
      list[index] = list[size];
      return num;
    }
    
    int main(){
      const time_t timer=time(NULL);
      printf("%s\n",ctime(&timer));
      
      srand( time(NULL));
      int x,y;
      for(int i=0;i<9;i++){
        x=Card();
        switch(x){
          case 1:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 2:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 3:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 4:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 5:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 6:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 7:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 8:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 9:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          }
        }
      getche();
    }
    
     
  12. askmewhy25

    askmewhy25 New Member

    Joined:
    Jan 24, 2010
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    0
    This is the shortest way that I know to make a random without repeating, the purpose of the GetNextNumber is for the flashcard but I replaced it with a new name with Card which represents the flashcards and the Side is for the sides of the flashcard. Now the problem is the repeating of the Side because it only prints for two flashcards after that it does not work anymore

    Here is my updated code:

    Code:
    #include<stdio.h>  
    #include <conio.h>
    #include <math.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    
    int Card(){
      static int list[9];
      static int size=-1;
      if(size==-1){
        size=9;
        for(int i=0;i<size;i++){ 
          list[i]=i+1;
          }
        }
      if(size==0){
        return 0;
        }
      int index=rand()%size;
      int num=list[index];
      size--;
      list[index] = list[size];
      return num;
    }
    
    int Side(){
      static int list[2];
      static int size=-1;
      if(size==-1){
        size=2;
        for(int i=0;i<size;i++){ 
          list[i]=i+1;
          }
        }
      if(size==0){
        return 0;
        }
      int index=rand()%size;
      int num=list[index];
      size--;
      list[index] = list[size];
      return num;
    }
    
    int main(){
      const time_t timer=time(NULL);
      printf("%s\n",ctime(&timer));
      
      srand( time(NULL));
      int x,y;
      for(int i=0;i<9;i++){
        x=Card();
        switch(x){
          case 1:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 2:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 3:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 4:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 5:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 6:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 7:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 8:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 9:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          }
        }
      getche();
    }
    
     
  13. askmewhy25

    askmewhy25 New Member

    Joined:
    Jan 24, 2010
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    0
    This is the shortest way that I know to make a random without repeating, the purpose of the GetNextNumber is for the flashcard but I replaced it with a new name with Card which represents the flashcards and the Side is for the sides of the flashcard. Now the problem is the repeating of the Side because it only prints for two flashcards after that it does not work anymore

    Here is my updated code:

    Code:
    #include<stdio.h>  
    #include <conio.h>
    #include <math.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    
    int Card(){
      static int list[9];
      static int size=-1;
      if(size==-1){
        size=9;
        for(int i=0;i<size;i++){ 
          list[i]=i+1;
          }
        }
      if(size==0){
        return 0;
        }
      int index=rand()%size;
      int num=list[index];
      size--;
      list[index] = list[size];
      return num;
    }
    
    int Side(){
      static int list[2];
      static int size=-1;
      if(size==-1){
        size=2;
        for(int i=0;i<size;i++){ 
          list[i]=i+1;
          }
        }
      if(size==0){
        return 0;
        }
      int index=rand()%size;
      int num=list[index];
      size--;
      list[index] = list[size];
      return num;
    }
    
    int main(){
      const time_t timer=time(NULL);
      printf("%s\n",ctime(&timer));
      
      srand( time(NULL));
      int x,y;
      for(int i=0;i<9;i++){
        x=Card();
        switch(x){
          case 1:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 2:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 3:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 4:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 5:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 6:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 7:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 8:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          case 9:
            printf("Passage Number: %d\n",x);
            for(int j=0;j<2;j++){
              y=Side();
              switch(y){
                case 1:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                case 2:
                  printf("Passage Number: %d\n",y);
                  getche();
                  break;
                }
              }
            getche();
            break;
          }
        }
      getche();
    }
    
     
  14. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Could you explain what you think Side() is doing and how it fits into the algorithm for the rest of the program? (I can see what Side() *is* doing, but I can't see what you *think* it's doing)
     
  15. askmewhy25

    askmewhy25 New Member

    Joined:
    Jan 24, 2010
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    0
    What I think Side() is doing is that the printing of the second side of the flashcard, my problem now is that Side() only works for two times and it does not reset.

    Here is the update codes:
    Code:
    #include <stdio.h>  
    #include <conio.h>
    #include <math.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    
    int Card(){
      static int list[9];
      static int size=-1;
      if(size==-1){
        size=9;
        for(int i=0;i<size;i++){ 
          list[i]=i+1;
          }
        }
      if(size==0){
        return 0;
        }
      int index=rand()%size;
      int num=list[index];
      size--;
      list[index]=list[size];
      return num;
    }
    
    int Side(){
      static int list[2];
      static int size=-1;
      if(size==-1){
        size=2;
        for(int i=0;i<size;i++){ 
          list[i]=i+1;
          }
        }
      if(size==0){
        return 0;
        }
      int index=rand()%size;
      int num=list[index];
      size--;
      list[index]=list[size];
      return num;
    }
    
    int main(){
      const time_t timer=time(NULL);
      printf("%s\n",ctime(&timer));
      
      srand(time(NULL));
      int x,y;
      for(int i=0;i<9;i++){
        x=Card();
        switch(x){
          case 1:
            system("cls");
            printf("Passage Number: %d\n\n",x);
            y=Side();
            switch(y){
              case 1:
                printf("2 Timothy 3:16-17\n\n");
                printf("Please press the spacebar to continue!!");
                getche();
                system("cls");
                printf("[16] All Scripture is God-breathed and is useful\n");
                printf("for teaching, rebuking, correcting and training\n");
                printf("in righteousness, [17] so that the man of God may be\n");
                printf("thoroughly equipped for every good work.\n\n");
                getche();              
                break;
              case 2:
                printf("[16] All Scripture is God-breathed and is useful\n");
                printf("for teaching, rebuking, correcting and training\n");
                printf("in righteousness, [17] so that the man of God may be\n");
                printf("thoroughly equipped for every good work.\n\n");
                printf("Please press the spacebar to continue!!");
                getche();
                system("cls");
                printf("2 Timothy 3:16-17\n\n");
                getche();
                break;
              }
            getche();
            break;
          case 2:
            system("cls");
            printf("Passage Number: %d\n\n",x);
            y=Side();
            switch(y){
              case 1:
                printf("Psalm 119:10-11\n\n");
                printf("Please press the spacebar to continue!!");
                getche();
                system("cls");           
                printf("[10] I seek you with all my heart do not let me\n");
                printf("stray from your commands.[11] I have hidden your\n");
                printf("word in my heartthat I might not sin against you.\n\n");
                getche();
                break;
              case 2:
                printf("[10] I seek you with all my heart do not let me\n");
                printf("stray from your commands.[11] I have hidden your\n");
                printf("word in my heartthat I might not sin against you.\n\n");
                printf("Please press the spacebar to continue!!");
                getche();
                system("cls");           
                printf("Psalm 119:10-11\n\n");
                getche();
                break;
              }
            getche();
            break;
          case 3:
            system("cls");
            printf("Passage Number: %d\n\n",x);
            y=Side();
            switch(y){
              case 1:
                printf("Hebrews 12:14\n\n");
                printf("Please press the spacebar to continue!!");
                getche();
                system("cls"); 
                printf("[14] Make every effort to live in peace with all men and\n");
                printf("to be holy without holiness no one will see the Lord.\n\n");
                getche();
                break;
              case 2:
                printf("[14] Make every effort to live in peace with all men and\n");
                printf("to be holy without holiness no one will see the Lord.\n\n");
                printf("Please press the spacebar to continue!!");
                getche();
                system("cls");
                printf("Hebrews 12:14\n\n");
                getche();            
                break;
              }
            getche();
            break;
          case 4:
            system("cls");
            printf("Passage Number: %d\n\n",x);
            y=Side();
            switch(y){
              case 1:
                printf("Romans 3:23\n\n");
                printf("Please press the spacebar to continue!!");
                getche();
                system("cls");
                printf("[23] for all have sinned and fall short of the glory of God,\n\n");
                getche();
                break;
              case 2:
                printf("[23] for all have sinned and fall short of the glory of God,\n\n");
                printf("Please press the spacebar to continue!!");
                getche();
                system("cls");
                printf("Romans 3:23\n\n");
                getche();
                break;
              }
            getche();
            break;
          case 5:
            system("cls");
            printf("Passage Number: %d\n\n",x);
            y=Side();
            switch(y){
              case 1:
                printf("Galatians 2:16\n\n");
                printf("Please press the spacebar to continue!!");
                getche();
                system("cls");
                printf("[16] know that a man is not justified by observing the law,\n");
                printf("but by faith in Jesus Christ. So we, too, have put our\n");
                printf("faith in Christ Jesus that we may be justified by faith\n");
                printf("in Christ and not by observing the law, because by observing\n");
                printf("the law no one will be justified.\n\n");
                getche();
                break;
              case 2:
                printf("[16] know that a man is not justified by observing the law,\n");
                printf("but by faith in Jesus Christ. So we, too, have put our\n");
                printf("faith in Christ Jesus that we may be justified by faith\n");
                printf("in Christ and not by observing the law, because by observing\n");
                printf("the law no one will be justified.\n\n");
                printf("Please press the spacebar to continue!!");
                getche();
                system("cls");
                printf("Galatians 2:16\n\n");
                getche();
                break;
              }
            getche();
            break;
          case 6:
            system("cls");
            printf("Passage Number: %d\n\n",x);
            y=Side();
            switch(y){
              case 1:
                printf("Ephesians 2:8-10\n\n");
                printf("Please press the spacebar to continue!!");
                getche();
                system("cls");
                printf("[8] For it is by grace you have been saved, through faith—and\n");
                printf("this not from yourselves, it is the gift of God — [9] not by\n");
                printf("works, so that no one can boast. [10] For we are God's\n");
                printf("workmanship, created in Christ Jesus to do good works,\n");
                printf("which God prepared in advance for us to do.\n\n");
                getche();
                break;
              case 2:
                printf("[8] For it is by grace you have been saved, through faith—and\n");
                printf("this not from yourselves, it is the gift of God — [9] not by\n");
                printf("works, so that no one can boast. [10] For we are God's\n");
                printf("workmanship, created in Christ Jesus to do good works,\n");
                printf("which God prepared in advance for us to do.\n\n");
                printf("Please press the spacebar to continue!!");
                getche();
                system("cls");
                printf("Ephesians 2:8-10\n\n");
                getche();
                break;
              }
            getche();
            break;
          case 7:
            system("cls");
            printf("Passage Number: %d\n\n",x);
            y=Side();
            switch(y){
              case 1:
                printf("1 Peter 2:9\n\n");
                printf("Please press the spacebar to continue!!");
                getche();
                system("cls");
                printf("[9] But you are a chosen people, a royal priesthood, a holy\n");
                printf("nation, a people belonging to God, that you may declare\n");
                printf("the praises of him who called you out of darkness into his\n");
                printf("wonderful light.\n\n");
                getche();
                break;
              case 2:
                printf("[9] But you are a chosen people, a royal priesthood, a holy\n");
                printf("nation, a people belonging to God, that you may declare\n");
                printf("the praises of him who called you out of darkness into his\n");
                printf("wonderful light.\n\n");
                printf("Please press the spacebar to continue!!");
                getche();
                system("cls");
                printf("1 Peter 2:9\n\n");
                getche();
                break;
              }
            getche();
            break;
          case 8:
            system("cls");
            printf("Passage Number: %d\n\n",x);
            y=Side();
            switch(y){
              case 1:
                printf("Romans 3:22-24\n\n");
                printf("Please press the spacebar to continue!!");
                getche();
                system("cls");
                printf("[22] This righteousness from God comes through faith in\n");
                printf("Jesus Christ to all who believe. There is no difference,\n");
                printf("[23] for all have sinned and fall short of the glory of God,\n");
                printf("[24] and are justified freely by his grace through the\n");
                printf("redemption that came by Christ Jesus.\n\n");
                getche();
                break;
              case 2:
                printf("[22] This righteousness from God comes through faith in\n");
                printf("Jesus Christ to all who believe. There is no difference,\n");
                printf("[23] for all have sinned and fall short of the glory of God,\n");
                printf("[24] and are justified freely by his grace through the\n");
                printf("redemption that came by Christ Jesus.\n\n");
                printf("Please press the spacebar to continue!!");
                getche();
                system("cls");
                printf("Romans 3:22-24\n\n");
                getche();
                break;
              }
            getche();
            break;
          case 9:
            system("cls");
            printf("Passage Number: %d\n\n",x);
            y=Side();
            switch(y){
              case 1:
                printf("John 3:16\n\n");
                printf("Please press the spacebar to continue!!");
                getche();
                system("cls");
                printf("[16] For God so loved the world that he gave his one and\n");
                printf("only Son, that whoever believes in him shall not perish\n");
                printf("but have eternal life.\n\n");
                getche();
                break;
              case 2:
                printf("[16] For God so loved the world that he gave his one and\n");
                printf("only Son, that whoever believes in him shall not perish\n");
                printf("but have eternal life.\n\n");
                printf("Please press the spacebar to continue!!");
                getche();
                system("cls");
                printf("John 3:16\n\n");
                getche();
                break;
              }
            getche();
            break;
          }
        }
      getche();
    }
    
     
  16. askmewhy25

    askmewhy25 New Member

    Joined:
    Jan 24, 2010
    Messages:
    49
    Likes Received:
    0
    Trophy Points:
    0
    Sir now I figured out the problem with the Side() I change it, here is may last problem

    *If correct, the user promotes the flashcard to box A. If incorrect, the user promotes the flashcard to box C.
    If the user is unsure or almost close to the correct one, the user promotes the flashcard to box B. The promotion is based on honest user input

    *After the user goes through all the flashcards, the program gives the user's score and stores it with its corresponding date and time.


    Here is my updated codes:
    Code:
    #include <stdio.h>  
    #include <conio.h>
    #include <math.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    
    typedef struct Box{
      int A;
      int B;
      int C;
    }Box;
    
    void Ans(int sel,Box z);
    
    int Card(){
      static int list[9];
      static int size=-1;
      if (size==-1){
        size=9;
        for(int i=0;i<size;i++){ 
          list[i]=i+1;
          }
        }
      if(size==0){
        return 0;
        }
      int index=rand()%size;
      int num=list[index];
      size--;
      list[index]=list[size];
      return num;
    }
    
    
    int Side(){
      int num;
      srand(time(NULL));
      num=1+(rand()%2);
      return num;
    }
    
    int main(){
      Box z;
      int x,y,sel;
      char error[128];
      const time_t timer=time(NULL);
      
      do{
          system("cls");
          printf("%s\n",ctime(&timer));
          printf("Selection Screen\n\n");
          printf("Flashcard Game\n");
          printf("1 - Play the Flashcard Game\n");
          printf("2 - Redo the Flashcards inside Box B and C\n\n");
          printf("Box Operation\n");
          printf("3 - Empty All the Boxes\n");
          printf("4 - Empty Box A\n");
          printf("5 - Empty Box B\n");
          printf("6 - Empty Box C\n\n");
          printf("Display All the Scores\n");
          printf("7 - Display All the Scores\n");
          printf("8 - Exit\n");
          fgets(error,128,stdin);
          sel=atoi(error);
          
          switch(sel){
            case 1:
              srand(time(NULL));
              for(int i=0;i<9;i++){
                x=Card();
                switch(x){
                  case 1:
                    system("cls");
                    printf("Passage Number: %d\n\n",x);
                    y=Side();
                    switch(y){
                      case 1:
                        printf("2 Timothy 3:16-17\n\n");
                        printf("Please press the spacebar to continue!!");
                        getche();
                        system("cls");
                        printf("[16] All Scripture is God-breathed and is useful\n");
                        printf("for teaching, rebuking, correcting and training\n");
                        printf("in righteousness, [17] so that the man of God may be\n");
                        printf("thoroughly equipped for every good work.\n\n");
                        getche();       
                        break;
                      case 2:
                        printf("[16] All Scripture is God-breathed and is useful\n");
                        printf("for teaching, rebuking, correcting and training\n");
                        printf("in righteousness, [17] so that the man of God may be\n");
                        printf("thoroughly equipped for every good work.\n\n");
                        printf("Please press the spacebar to continue!!");
                        getche();
                        system("cls");
                        printf("2 Timothy 3:16-17\n\n");
                        getche();
                        break;
                      }
                    break;
                  case 2:
                    system("cls");
                    printf("Passage Number: %d\n\n",x);
                    y=Side();
                    switch(y){
                      case 1:
                        printf("Psalm 119:10-11\n\n");
                        printf("Please press the spacebar to continue!!");
                        getche();
                        system("cls");           
                        printf("[10] I seek you with all my heart do not let me\n");
                        printf("stray from your commands.[11] I have hidden your\n");
                        printf("word in my heartthat I might not sin against you.\n\n");
                        getche();
                        break;
                      case 2:
                        printf("[10] I seek you with all my heart do not let me\n");
                        printf("stray from your commands.[11] I have hidden your\n");
                        printf("word in my heartthat I might not sin against you.\n\n");
                        printf("Please press the spacebar to continue!!");
                        getche();
                        system("cls");           
                        printf("Psalm 119:10-11\n\n");
                        getche();
                        break;
                      }
                    break;
                  case 3:
                    system("cls");
                    printf("Passage Number: %d\n\n",x);
                    y=Side();
                    switch(y){
                      case 1:
                        printf("Hebrews 12:14\n\n");
                        printf("Please press the spacebar to continue!!");
                        getche();
                        system("cls"); 
                        printf("[14] Make every effort to live in peace with all men and\n");
                        printf("to be holy without holiness no one will see the Lord.\n\n");
                        getche();
                        break;
                      case 2:
                        printf("[14] Make every effort to live in peace with all men and\n");
                        printf("to be holy without holiness no one will see the Lord.\n\n");
                        printf("Please press the spacebar to continue!!");
                        getche();
                        system("cls");
                        printf("Hebrews 12:14\n\n");
                        getche();            
                        break;
                      }
                    break;
                  case 4:
                    system("cls");
                    printf("Passage Number: %d\n\n",x);
                    y=Side();
                    switch(y){
                      case 1:
                        printf("Romans 3:23\n\n");
                        printf("Please press the spacebar to continue!!");
                        getche();
                        system("cls");
                        printf("[23] for all have sinned and fall short of the glory of God,\n\n");
                        getche();
                        break;
                      case 2:
                        printf("[23] for all have sinned and fall short of the glory of God,\n\n");
                        printf("Please press the spacebar to continue!!");
                        getche();
                        system("cls");
                        printf("Romans 3:23\n\n");
                        getche();
                        break;
                      }
                    break;
                  case 5:
                    system("cls");
                    printf("Passage Number: %d\n\n",x);
                    y=Side();
                    switch(y){
                      case 1:
                        printf("Galatians 2:16\n\n");
                        printf("Please press the spacebar to continue!!");
                        getche();
                        system("cls");
                        printf("[16] know that a man is not justified by observing the law,\n");
                        printf("but by faith in Jesus Christ. So we, too, have put our\n");
                        printf("faith in Christ Jesus that we may be justified by faith\n");
                        printf("in Christ and not by observing the law, because by observing\n");
                        printf("the law no one will be justified.\n\n");
                        getche();
                        break;
                      case 2:
                        printf("[16] know that a man is not justified by observing the law,\n");
                        printf("but by faith in Jesus Christ. So we, too, have put our\n");
                        printf("faith in Christ Jesus that we may be justified by faith\n");
                        printf("in Christ and not by observing the law, because by observing\n");
                        printf("the law no one will be justified.\n\n");
                        printf("Please press the spacebar to continue!!");
                        getche();
                        system("cls");
                        printf("Galatians 2:16\n\n");
                        getche();
                        break;
                      }
                    break;
                  case 6:
                    system("cls");
                    printf("Passage Number: %d\n\n",x);
                    y=Side();
                    switch(y){
                      case 1:
                        printf("Ephesians 2:8-10\n\n");
                        printf("Please press the spacebar to continue!!");
                        getche();
                        system("cls");
                        printf("[8] For it is by grace you have been saved, through faith—and\n");
                        printf("this not from yourselves, it is the gift of God — [9] not by\n");
                        printf("works, so that no one can boast. [10] For we are God's\n");
                        printf("workmanship, created in Christ Jesus to do good works,\n");
                        printf("which God prepared in advance for us to do.\n\n");
                        getche();
                        break;
                      case 2:
                        printf("[8] For it is by grace you have been saved, through faith—and\n");
                        printf("this not from yourselves, it is the gift of God — [9] not by\n");
                        printf("works, so that no one can boast. [10] For we are God's\n");
                        printf("workmanship, created in Christ Jesus to do good works,\n");
                        printf("which God prepared in advance for us to do.\n\n");
                        printf("Please press the spacebar to continue!!");
                        getche();
                        system("cls");
                        printf("Ephesians 2:8-10\n\n");
                        getche();
                        break;
                      }
                    break;
                  case 7:
                    system("cls");
                    printf("Passage Number: %d\n\n",x);
                    y=Side();
                    switch(y){
                      case 1:
                        printf("1 Peter 2:9\n\n");
                        printf("Please press the spacebar to continue!!");
                        getche();
                        system("cls");
                        printf("[9] But you are a chosen people, a royal priesthood, a holy\n");
                        printf("nation, a people belonging to God, that you may declare\n");
                        printf("the praises of him who called you out of darkness into his\n");
                        printf("wonderful light.\n\n");
                        getche();
                        break;
                      case 2:
                        printf("[9] But you are a chosen people, a royal priesthood, a holy\n");
                        printf("nation, a people belonging to God, that you may declare\n");
                        printf("the praises of him who called you out of darkness into his\n");
                        printf("wonderful light.\n\n");
                        printf("Please press the spacebar to continue!!");
                        getche();
                        system("cls");
                        printf("1 Peter 2:9\n\n");
                        getche();
                        break;
                      }
                    break;
                  case 8:
                    system("cls");
                    printf("Passage Number: %d\n\n",x);
                    y=Side();
                    switch(y){
                      case 1:
                        printf("Romans 3:22-24\n\n");
                        printf("Please press the spacebar to continue!!");
                        getche();
                        system("cls");
                        printf("[22] This righteousness from God comes through faith in\n");
                        printf("Jesus Christ to all who believe. There is no difference,\n");
                        printf("[23] for all have sinned and fall short of the glory of God,\n");
                        printf("[24] and are justified freely by his grace through the\n");
                        printf("redemption that came by Christ Jesus.\n\n");
                        getche();
                        break;
                      case 2:
                        printf("[22] This righteousness from God comes through faith in\n");
                        printf("Jesus Christ to all who believe. There is no difference,\n");
                        printf("[23] for all have sinned and fall short of the glory of God,\n");
                        printf("[24] and are justified freely by his grace through the\n");
                        printf("redemption that came by Christ Jesus.\n\n");
                        printf("Please press the spacebar to continue!!");
                        getche();
                        system("cls");
                        printf("Romans 3:22-24\n\n");
                        getche();
                        break;
                      }
                    break;
                  case 9:
                    system("cls");
                    printf("Passage Number: %d\n\n",x);
                    y=Side();
                    switch(y){
                      case 1:
                        printf("John 3:16\n\n");
                        printf("Please press the spacebar to continue!!");
                        getche();
                        system("cls");
                        printf("[16] For God so loved the world that he gave his one and\n");
                        printf("only Son, that whoever believes in him shall not perish\n");
                        printf("but have eternal life.\n\n");
                        getche();
                        break;
                      case 2:
                        printf("[16] For God so loved the world that he gave his one and\n");
                        printf("only Son, that whoever believes in him shall not perish\n");
                        printf("but have eternal life.\n\n");
                        printf("Please press the spacebar to continue!!");
                        getche();
                        system("cls");
                        printf("John 3:16\n\n");
                        getche();
                        break;
                      }
                    break;
                  }
                }
              system("cls");
              printf("Your score is %d: ",z.A);
              break;
            case 2:
              break;
            case 3:
              break;
            case 4:
              break;
            case 5:
              break;
            case 6:
              break;
            case 7:
              break;
            case 8://Exit
              exit(1);
              break;
            default://Program redirects the invalid input
              system("cls");
              printf("Invalid input. Please try again!!!\n");
              printf("Please press the spacebar to continue!!");
              getche();
              break;
            }
      
      }while(sel!=8);
    }
    
    void Ans(int sel,Box z){
      char error[128];
      printf("Which box do you want to promote the flashcard?\n\n");
      printf("1 - Box A for Correct Answer");
      printf("2 - Box B for Unsure Answer");
      printf("3 - Box C for Invalid Answer");
      scanf("%s",&error);
      sel=atoi(error);
      switch(sel){
        case 1:
          z.A=z.A+1;
          break;
        case 2:
          z.B=z.B+1;
          break;
        case 3:
          z.C=z.C+1;
          break;
        }
    }
    
     
    Last edited: Mar 20, 2010

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice