0

私は新しい C++ プログラマーです。電卓を作成していますが、void printAnswer()関数に問題があります。関数を呼び出してパラメーター (double変数) を入力すると、関数名は常に変数識別子に変わります。コンパイルすると、

重大度コード 説明 プロジェクト ファイル行抑制状態  
エラー (アクティブ) E0070 不完全な型は使用できません 電卓 C:\Users\jk\Downloads\Coding Stuff\Calculator\Calculator.cpp 17  
エラー C2182 'printAnswer': タイプ 'void' Calculator C:\Users\jk\Downloads\Coding Stuff\Calculator\Calculator.cpp 17 の不正な使用  
警告 C4244 '初期化中': 'double' から 'int' への変換、データ損失の可能性 Calculator C:\Users\jk\Downloads\Coding Stuff\Calculator\Calculator.cpp 17  

これは私のヘッダーファイルです。

#ifndef CALCULATOR_H

#define CALCULATOR_H

void calculator();
double getValue1(double);
double getValue2(double);
std::string getOperation(std::string);
double calculation(double, double, std::string);
void printAnswer(double);

#endif

これは私のメインファイルです

#include <iostream>
#include <string>
#include "Calculator.h"

int main()
{
    double a{};
    double b{};
    double x{ getValue1(a) };
    std::string calculatorOperation{};
    std::string operation{ getOperation(calculatorOperation) };
    double y{ getValue2(b) };
    double answer{ calculation( x, y, operation ) };
    void printAnswer(answer);
   /*
    *   if (answer == 99999999999999999.999)
    *        std::cout << "Sorry. The desired operation does not exist or you have misspelled 
somthing.\n";
    *    else
    *        std::cout << "The answer is " << answer << ".\n";
    *
    *    return 0;
    */

}

double getValue1(double x)
{
    std::cout << "Please type your first number and press enter.\n";
    std::cin >> x;
    return x;
}

double getValue2(double y)
{
    std::cout << "Please type your second number and press enter.\n";
    std::cin >> y;
    return y;
}

std::string getOperation(std::string operation)
{
    std::cout << "Please type in the desired operation in all undercase and press enter.\n";
    std::cin >> operation;
    return operation;
}

double calculation(double x, double y, std::string operation)
{
    if (operation == "addition")
        return x + y;
    else if (operation == "subtraction")
        return x - y;
    else if (operation == "multiplication")
        return x * y;
    else if (operation == "division")
        return x / y;
    else
        return 99999999999999999.999;
}

void printAnswer(double answer)
{
    if (answer == 99999999999999999.999)
        std::cout << "Sorry. The desired operation does not exist or you have misspelled somthing.\n";
    else
        std::cout << "The answer is " << answer << ".\n";
}   
4

1 に答える 1