Thread: How can i create algoritma for this question

  1. #1
    Registered User
    Join Date
    Dec 2021
    Posts
    5

    How can i create algoritma for this question

    In this part of the project, main purpose is to get the secret code from the computer. There are five questions to be answered. In each question, user will face a problem and all problems are related to the solution of the previous problem. Before solving the problem, it is not possible to move to the next question. First question will start with the day the user was born. That means each code is specific for each user. When user reaches and solves the fifth problem he/she will get the key code.
    Here are the questions:
    1) Please enter the numeric day of your birthday between 1 and 7 (example Mon=1, Tue=2). If user enters number that is not between 1 and 7, then print error and ask number again.
    Lets assume the result of question 1 is x.
    2) What is the xth power of n (i.e. nx)? Here, n is a number that can only be computed as follows:
    Get the initial letter of your name in uppercase (A to Z, others will not be tested). Look at the decimal number that stands for that letter in ASCII table and take the mod of it by 4.
    Hint: There is no need to look at the ASCII table, actually. Both in Labs and MT1, we have shown you the trick.
    For example, Oguzhan is my name. Initial letter of my name is O. The number stands for that letter in ASCII table is 79. mod(79,4) = 3. Hence, n = 3.
    Also you have to print both the letter and the value n on screen. In order to print in correct way, examine the example below.
    Lets assume the result of question 2 is y.
    3) How many prime numbers do exist until y? (y is included.)
    Hint: A prime number is a whole number greater than 1 that has no positive divisors other than 1 and itself.

    For example, there are 9 prime numbers until 27.

    Lets assume the result of question 3 is z.
    4) Enter zth element of Fibonacci series.
    Hint: Fibonacci series is a series of numbers in which each number (Fibonacci number) is the sum of the two preceding numbers. A part of the series is 1, 1, 2, 3, 5, 8,

    For example, if z==6, then w=8 .

    Lets assume the result of question 4 is w.
    5) Finally enter your age and compute wage ( is multiplication sign), which is the desired keycode.
    Remember that program should continue until user enters a correct answer for each question. For 5th question, age should be between 1 and 100, if it is not, you are expected to print the error and ask again.
    After 5th question is correctly answered, print Congratulations! You found the code! The code is
    Youre expected to implement the functions below (of course with some parameters and proper return types):

    • askFirstQuestion()
    • askSecondQuestion()
    • askThirdQuestion()
    • askFourthQuestion()
    • askFifthQuestion()

    In addition to these methods you can also implement more functions.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,152
    There isn't much to do except follow the instructions.

    I mean it's all printf / scanf and some simple maths.

    > You’re expected to implement the functions below (of course with some parameters and proper return types):
    So do the first one
    - write some code
    - compile it
    - test it.

    You keep doing those things until you're happy that askFirstQuestion() is working properly.

    Then you do the whole thing over for askSecondQuestion()

    And so on.

    Post when you have code and are stuck.
    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.

  3. #3
    Registered User
    Join Date
    Dec 2021
    Posts
    5
    i wrote the code for the first quesiton but idk how to use the output of the first question as a input in second question

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,152
    So show us what you have.
    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.

  5. #5
    Registered User
    Join Date
    Dec 2021
    Posts
    5
    How can i create algoritma for this question-newcode-jpg

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,152
    Copy/paste the code in [code][/code] tags.

    Fuzzy pictures are useless for quoting text.
    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.

  7. #7
    Registered User
    Join Date
    Dec 2021
    Posts
    5
    Code:
    #include <stdio.h>#include <stdlib.h>
    
    
    
    
    int askFirstQuestion(int a){
    
    
    	return (a>=1 && a<=7);
    }
    	int main() {
    	int a;
    	printf("1) Please enter your birthday between 1 and 7(example Mon=1, Tue=2..):");	 
    	scanf("%d",&a);
    
    
    	
    	if(a>=1 && a<=7){
    	
    printf("%d\n",a);
    	
    }
    else{
    	while(!(askFirstQuestion(a))){
    	
    	printf("%d\nPlease enter an appropriate day!\n",a);
    	scanf("%d",&a);
    	if(askFirstQuestion(a)){
    		printf("%d\n",a);
    		
    	}
    }
    	return 0;
    
    
    	
    }
    
    
    	
    	
    
    
    	
    
    
    	
    	
    	
    	
    }

  8. #8
    Registered User
    Join Date
    Dec 2021
    Posts
    5
    And i need to ask second quesiton to the user but idk how to do it when i use second scanf it doesnt work program just take the first input and stops

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,152
    First off, fix your indentation, it's all over the place.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int askFirstQuestion(int a)
    {
      return (a >= 1 && a <= 7);
    }
    
    int main()
    {
      int a;
      printf("1) Please enter your birthday between 1 and 7(example Mon=1, Tue=2..):");
      scanf("%d", &a);
      if (a >= 1 && a <= 7) {
        printf("%d\n", a);
      } else {
        while (!(askFirstQuestion(a))) {
          printf("%d\nPlease enter an appropriate day!\n", a);
          scanf("%d", &a);
          if (askFirstQuestion(a)) {
            printf("%d\n", a);
          }
        }
        return 0;
      }
    }
    Most of the code you have in main should be inside the function.
    It should be the one to print the prompt, get an answer and loop until the answer is within range.

    So your main should be
    Code:
    int main( ) {
      int birth_day = askFirstQuestion();
    }
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 08-18-2010, 06:12 AM
  2. question on create a crc16 table
    By mycount in forum Tech Board
    Replies: 3
    Last Post: 08-29-2006, 08:03 PM
  3. Create() question
    By dhrodrigues in forum Windows Programming
    Replies: 3
    Last Post: 07-19-2004, 01:40 PM
  4. Create Array size Question
    By popohoma in forum C++ Programming
    Replies: 3
    Last Post: 11-04-2002, 03:04 AM

Tags for this Thread