Question

Haskell code: checkIfEven :: Int -> Bool x <- readLn let checkIfEven x = (even ((x*3)+1))...

Haskell code:

checkIfEven :: Int -> Bool
x <- readLn
let checkIfEven x = (even ((x*3)+1))
print checkIfEven   

Getting error :  Variable not in scope: checkIfEven :: Int -> Bool, how to fix it?
note: function goal is take an int and return a bool.

takes the integer multiplies it by 3 and adds 1. if the the outcome is even return true, otherwise false.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have rectified the error

checkIfEven :: Int -> Bool

checkIfEven x = (even ((x*3)+1))

main = do

x <- readLn

print(checkIfEven x)

Output

10 False checkIfEven :: Int -> Bool checkIfEven x = (even ((x+3)+1)) main = do X <- readln print(checkIfEven x)

Add a comment
Know the answer?
Add Answer to:
Haskell code: checkIfEven :: Int -> Bool x <- readLn let checkIfEven x = (even ((x*3)+1))...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • • bool test(int a, int& b) { bool res = false; if(a > b) { b...

    • bool test(int a, int& b) { bool res = false; if(a > b) { b = a%2; res = true; } return res; } int main() { int x = 45, y = 43; test(x, y); cout << x << " " << y << endl; return 0; } Question: The output of the above code is: ________________ •Write a function that takes an integer as its sole parameter and returns -1, 0 or 1 depending upon whether the...

  • haskell code: divisableBy3 :: [a] -> [a] divisableBy3 v = filter odd(filter(\v -> v 'mod' 3...

    haskell code: divisableBy3 :: [a] -> [a] divisableBy3 v = filter odd(filter(\v -> v 'mod' 3 == 0)) Goal to filter all numbers in a list and then filter to keep only the ones divisbable by 3. getting an error: error: * Syntax error on 'mod' Perhaps you intended to use TemplateHaskell or TemplateHaskellQuotes * In the Template Haskell quotation 'mod' | 7 | divisableBy3 v = filter odd(filter(\v -> v 'mod' 3 == 0)) | ^^^^^ how to fix...

  • QUESTION 1 What is the output of the following code snippet? int main() { bool attendance...

    QUESTION 1 What is the output of the following code snippet? int main() { bool attendance = false; string str = "Unknown"; attendance = !(attendance); if (!attendance) { str = "False"; } if (attendance) { attendance = false; } if (attendance) { str = "True"; } else { str = "Maybe"; } cout << str << endl; return 0; } False True Unknown Maybe QUESTION 2 What is the output of the following code snippet? #include <iostream> #include <string> using...

  • In C++ #include<iostream> using namespace std; //Implement the function below. bool is_fibonacci_array(int*,int); //Param 1: pointer to...

    In C++ #include<iostream> using namespace std; //Implement the function below. bool is_fibonacci_array(int*,int); //Param 1: pointer to the beginning of an array of integers //Param 2: size of that array //Returns: true, is every element in the input array is a Fibonacci number //(the order of the numbers in the array need not be ordered //as per the Fibonacci sequence) //false, otherwise //A Fibonacci sequence is generated as follows. //The first two numbers in the sequence are 0 and 1. //The...

  • Using C++ Question#1: isPalíndrome Write the following function: bool isPalindrome(int) takes an integer and returns true...

    Using C++ Question#1: isPalíndrome Write the following function: bool isPalindrome(int) takes an integer and returns true if that integer is palindrome, otherwise it returns false. The function also prints the digits of the integer in reverse order in which they were found. Write a main) function that reads an integer, calls the function is whether the integer is a palindrome or not. Palindrome), and prints Sample input/output: nter an integer: 23434 nter an integer 23432 3434 is not a palindrome...

  • a) Make a function which returns x/3 with a given integer x. double third(int x) {...

    a) Make a function which returns x/3 with a given integer x. double third(int x) { //Complete your code below. ______________________________________ return y; } b) Make a program which shows 2 ∗ n with a given user input n. #include<iostream> using namespace std; // Complete the blank. _______________________ int main(){ int n; cout<<"Enter:"; cin>>n; cout<<twice(n); return 0; } int twice(int x){ return 2*x; } c) Make a function which returns true if n is positive, otherwise returns false. ________ positive(int...

  • How do can I update this code (Code A): Code (A) #include using namespace std; int fibonacci(int n) { int a = 0,...

    How do can I update this code (Code A): Code (A) #include using namespace std; int fibonacci(int n) { int a = 0, b = 1, c; if (n <= 1) return n; for (int i = 2; i <= n; i++) { c = a + b; a = b; b = c; } return b; } int fibonacciRecursive(int n) { if (n <= 1) { return n; } return fibonacciRecursive(n-1) + fibonacciRecursive(n-2); } int main() { int n;...

  • *Please write in code in C* First, write a function called prime_check(int x) that takes an...

    *Please write in code in C* First, write a function called prime_check(int x) that takes an integer number as an input then return 1 if it is a prime number nd returns 0 if it is a composite number Then, Write a program that prompt the user to input two numbers: Print the multiplication of these two numbers if both of them are prime. Or Print " Sorry at least one of your number is composite" if otherwise

  • Starting code: #include <stdio.h> #include <stdbool.h> #include <assert.h> bool checkSudoku(int sudoku[9][9]) { //code goes here }...

    Starting code: #include <stdio.h> #include <stdbool.h> #include <assert.h> bool checkSudoku(int sudoku[9][9]) { //code goes here } int main() { int sudoku[9][9] = {{7, 3, 5, 6, 1, 4, 8, 9, 2}, {8, 4, 2, 9, 7, 3, 5, 6, 1}, {9, 6, 1, 2, 8, 5, 3, 7, 4}, {2, 8, 6, 3, 4, 9, 1, 5, 7}, {4, 1, 3, 8, 5, 7, 9, 2, 6}, {5, 7, 9, 1, 2, 6, 4, 3, 8}, {1, 5, 7, 4,...

  • #include <iostream> #include <fstream> using namespace std; //constants const int CAP = 100; //function prototypes bool...

    #include <iostream> #include <fstream> using namespace std; //constants const int CAP = 100; //function prototypes bool openFile(ifstream &); void readData(ifstream &, int [], int &); void printData(const int [], int); void sum(const int[], int); void removeItem(int[], int &, int); int main() { ifstream inFile; int list[CAP], size = 0; if (!openFile(inFile)) { cout << "Program terminating!! File not found!" << endl; return -1; } //read the data from the file readData(inFile, list, size); inFile.close(); cout << "Data in file:" <<...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT