Thread: Need help (maybe it's loops i need, dunno)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    4

    Arrow Need help (maybe it's loops i need, dunno)

    Hi guys,
    I have run into a small problem. I am trying to make this "daily planner" thing and I have a question.

    Code:
    #include <stdio.h>
    #include <string.h>
    
    
    int main (void)
    {
        int points;
        int score;
        points = 5;
        score = 0;
       
        const char *key1 = "Monday";
        const char *key2 = "Tuesday";
        const char *key3 = "Wednesday";
        const char *key4 = "Thursday";
        const char *key5 = "Friday";
        const char *key6 = "Saturday";
        const char *key7 = "Sunday";
        char day[10]; 
        
        printf("Your current score is: %d.\n", score);
        printf("What day is it today?\n");
        scanf("%s", day);
       
        if(strcmp (key1, day) ==0){
                 printf("Do this and this");
                 } else if (strcmp (key2, day) ==0) {
                        printf("Do this and this");
                       } else if (strcmp (key3, day) ==0) {
                              printf("Do this and this");
                           } else if (strcmp (key4, day) ==0) {
                                  printf("Do this and this");
                               } else if (strcmp (key5, day) ==0) {
                                      printf("Do this and this");
                                    } else if (strcmp (key6, day) ==0) {
                                           printf("Do this and this");
                                        } else if (strcmp (key7, day) ==0) {
                                               printf("Do this and this");
                                            } else {
                                                   printf("You mistyped! English mother........er, do you speak it?");
                                                   
                                                   }
                                                   
        printf("\nHave you done what you planned to accomplish?\n");
        const char *answer = "yes";
        char input[4];
        scanf ("%s", input);
        if(strcmp (input, answer)==0){
                  printf("Congratulations! You have scored 5 points!");
                  score=score+points;
                  }
                  else {
                       printf("\nWell, try harder then!");
                       }
        
        
    getchar();
    getchar();
    return 0;
    
    
    }

    Firstly: how do I make the loop so that at the mistype moment the program goes back to the question "what day is it?"? should I put the whole if and if else block into a loop or just some part of it?

    Secondly: I really dislike having to write out all of those if and if else statements :/ is there a way around it? I read up on it and some people said switch statements don't work but maybe there is something else?

    Thirdly: is there a simple way for the program to retain the memory of my score? So that when the program terminates the score is still stored somewhere?

    Thanks!
    Last edited by OmenOfDefeat; 02-07-2016 at 08:10 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dunno what to do
    By Joemar P. Gava in forum C Programming
    Replies: 8
    Last Post: 09-19-2014, 02:53 AM
  2. Some error, dunno what
    By suvojit biswas in forum C Programming
    Replies: 1
    Last Post: 10-04-2012, 09:36 AM
  3. 2 for loops...dunno why its skipping loop 2
    By Axolotl in forum C Programming
    Replies: 3
    Last Post: 04-03-2003, 02:07 PM
  4. i dunno how to do loops and functions together
    By Noobie in forum C++ Programming
    Replies: 30
    Last Post: 02-03-2003, 06:05 PM
  5. I now have the DX SDK (and I dunno how to.......)
    By Stealth in forum C++ Programming
    Replies: 6
    Last Post: 11-06-2001, 08:09 PM

Tags for this Thread