Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void ft_modulus (int n1, int n2);
- void ft_multiplication (int n1, int n2);
- void ft_division (int n1, int n2);
- int main()
- {
- printf("#####****MATHS CHECKER****######\n");
- //user prompt
- printf("MENU\n");
- //menu options
- printf("1 => MODULUS\n");
- printf("2 => MULTIPLICATION\n");
- printf("3 => DIVISION\n");
- printf("4 => EXIT\n");
- int num1, num2;
- //user prompt
- printf("Enter 2 random numbers.\n");
- scanf("%d%d", &num1, &num2);
- int option;
- //user prompt
- printf("Choose an operation from menu above to be performed on the numbers:\n");
- scanf("%d", &option);
- switch (option)
- {
- case 1: ft_modulus(num1, num2);
- break;
- case 2: ft_multiplication(num1, num2);
- break;
- case 3: ft_division(num1, num2);
- break;
- case 4: break;
- }
- return 0;
- }
- void ft_modulus(int n1, int n2)
- {
- int correctAnswer, userAnswer, newAnswer;
- correctAnswer = n1%n2;
- //user prompt
- printf("Enter answer you got:\n");
- scanf("%d", &userAnswer);
- if (userAnswer == correctAnswer)
- {
- printf("Congrats!!!Your answer is correct.\n");
- }
- else if (userAnswer != correctAnswer)
- {
- printf("Incorrect:(Please try again.\n");
- printf("Enter new answer:\n");
- scanf("%d", &newAnswer);
- if (newAnswer == correctAnswer)
- {
- printf("Congrats!!!Your answer is correct.\n");
- }
- else if (newAnswer != correctAnswer);
- {
- printf("Incorrect:(You have exhausted all your chances.\n");
- printf("%d %% %d = %d", n1, n2, correctAnswer);
- }
- }
- }
- void ft_multiplication (int n1, int n2)
- {
- int correctAnswer, userAnswer, newAnswer;
- correctAnswer = n1*n2;
- //user prompt
- printf("Enter answer you got:\n");
- scanf("%d", &userAnswer);
- if (userAnswer == correctAnswer)
- {
- printf("Congrats!!!Your answer is correct.\n");
- }
- else if (userAnswer != correctAnswer)
- {
- printf("Incorrect:(Please try again.\n");
- printf("Enter new answer:\n");
- scanf("%d", &newAnswer);
- if (newAnswer == correctAnswer)
- {
- printf("Congrats!!!Your answer is correct.\n");
- }
- else if (newAnswer != correctAnswer);
- {
- printf("Incorrect:(You have exhausted all your chances.\n");
- printf("%d * %d = %d", n1, n2, correctAnswer);
- }
- }
- }
- void ft_division (int n1, int n2)
- {
- int correctAnswer, userAnswer, newAnswer;
- correctAnswer = n1/n2;
- //user prompt
- printf("Enter answer you got:\n");
- scanf("%d", &userAnswer);
- if (userAnswer == correctAnswer)
- {
- printf("Congrats!!!Your answer is correct.\n");
- }
- else if (userAnswer != correctAnswer)
- {
- printf("Incorrect:(Please try again.\n");
- printf("Enter new answer:\n");
- scanf("%d", &newAnswer);
- if (newAnswer == correctAnswer)
- {
- printf("Congrats!!!Your answer is correct.\n");
- }
- else if (newAnswer != correctAnswer);
- {
- printf("Incorrect:(You have exhausted all your chances.\n");
- printf("%d / %d = %d", n1, n2, correctAnswer);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement