저는 F #으로 계산기를 만들려고합니다. 그래서 나는 수행 할 작업과 관련하여 사용자로부터 의견을받습니다. 입력 6의 경우 과학적 조작을위한 메뉴가 표시되어야하지만 표현식에는 유형 단위가 있어야하지만 유형은 float이어야합니다. 그리고 scientificFun() 함수에서도 마지막 행에 대해 '표현식에 부동 소수점이 있어야하지만 여기에는 단위가 있습니다.'라고 표시됩니다. 나는 그것이 무엇을 의미하는지 모르겠습니다. 이걸 몇 시간 동안 붙잡 았어. 어떤 도움을 주시면 감사하겠습니다. 감사!. ** 또는 굵은 선은 오류가 발생한 위치를 나타냅니다.F # 오류 : 표현식이 단위 유형을 가져야합니다.
open System
let mutable ok = true
while ok do
Console.WriteLine("Choose a operation:\n1.Addition\n2.Substraction\n3.Multiplication\n4.Division\n5.Modulo\n6.Scientific")
let input= Console.ReadLine()
let add() =
Console.WriteLine("Ok, how many numbers?")
let mutable count = int32(Console.ReadLine())
let numberArray = Array.create count 0.0
for i in 0 .. numberArray.Length - 1 do
let no = float(Console.ReadLine())
Array.set numberArray i no
Array.sum numberArray
let expo() =
Console.WriteLine("Enter the base")
let getBase = Console.ReadLine()
Console.WriteLine("Enter the exponent")
let getExponent = Console.ReadLine()
float(getBase) ** float(getExponent)
let sqRoot() =
Console.WriteLine("Enter a number")
let no = float(Console.ReadLine())
Math.Sqrt no
let rec fact (n:float) =
if n < 1.0 then 1.0
else n * fact (n - 1.0)
let factorial() =
Console.WriteLine("Enter a number")
let no = float(Console.ReadLine())
fact(no)
let Trigsin() =
Console.WriteLine("Enter an angle")
let angle = float(Console.ReadLine())
Math.Sin angle
let Trigcos() =
Console.WriteLine("Enter an angle")
let angle = float(Console.ReadLine())
Math.Cos angle
let Trigtan() =
Console.WriteLine("Enter an angle")
let angle = float(Console.ReadLine())
Math.Tan angle
let logicalAnd() =
Console.WriteLine("Enter first number")
let first = int32(Console.ReadLine())
Console.WriteLine("Enter second number")
let second = int32(Console.ReadLine())
float(first &&& second)
let logicalOr() =
Console.WriteLine("Enter first number")
let first = int(Console.ReadLine())
Console.WriteLine("Enter second number")
let second = int(Console.ReadLine())
float(first ||| second)
let logicalNot()=
Console.WriteLine("Enter a number")
let first = int32(Console.ReadLine())
float(~~~first)
let sub x y = x - y
let mul x y = x * y
let div x y = x/y
let MOD x y = x % y
let scientificFun() =
printfn("1.Exponential\n2.Square Root\n3.Factorial\n4.sin()\n5.cos()\n6.tan()\n7.AND\n8.OR\n9.NOT")
let scientificInput = Console.ReadLine()
match scientificInput with
|"1" -> expo()
|"2" -> sqRoot()
|"3" -> factorial()
|"4" -> Trigsin()
|"5" -> Trigcos()
|"6" -> Trigtan()
|"7" -> logicalAnd()
|"8" -> logicalOr()
|"9" -> logicalNot()
| _ -> **printfn("Choose between 1 - 9")**
match input with
| "1" -> printfn("The Result is: %f") (add())
//| "2" -> printfn("The Result is: %f") (sub A B)
//| "3" -> printfn("The Result is: %f") (mul A B)
///| "4" -> printfn("The Result is: %f") (div A B)
//| "5" -> printfn("The Result is: %f") (MOD A B)
| "6" -> **scientificFun()**
| _-> printfn("Choose between 1 and 6")
Console.WriteLine("Would you like to use the calculator again? y/n")
let ans = Console.ReadLine()
if ans = "n" then
ok <- false
else Console.Clear()
[최소, 완전하며 인증 가능한 예] (http://stackoverflow.com/help/mcve)를 게시하십시오. –
패턴 일치의 모든 리턴 값은 동일한 유형이어야합니다. 'scientificInput'과 일치하는 곳에서는 모든 함수가'unit '을 반환하는'printfn'을 제외하고'float', 을 반환합니다. – Funk
Thanks @ Funk .. 내가 어떻게이 일을 할 수 있는지에 대한 아이디어를 줄 수 있니?. 6을 누르면 과학 메뉴가 표시됩니다. –