2013-10-07 2 views
-1

나는 새로운 C++ 학생이며 기초 수학을 배우는 아이들을위한 기본 프로그램을 만들고자합니다. 이것은 진행중인 작업이므로 일부 코드는 완료되지 않았습니다. 지금까지 한 것을 컴파일하려고하는데 다음과 같은 오류가 발생합니다. 47 59 [오류] 새 선언 'void add (int, int, std :: string, char)'AND 18 5 [Error] ambiguates 오래된 선언 'INT 추가 기능 (INT, INT, 표준 : : 문자열, 문자)'함수의 인자

#include <iostream> 
#include <iomanip> 
#include <time.h> 
#include <string> 
#include <cstdlib> 
#define over2 "\t\t" 
#define over3 "\t\t\t" 
#define over4 "\t\t\t\t" 
#define down5 "\n\n\n\n\n" 
#define down8 "\n\n\n\n\n\n\n\n" 
#define down10 "\n\n\n\n\n\n\n\n\n\n" 
#define down12 "\n\n\n\n\n\n\n\n\n\n\n\n" 

using namespace std; 

int add(int,int,string,char); 
int sub(); 
int multi(); 
int div(); 

int main(int argc, char** argv) 


{ 
    int num1, num2; 

    unsigned seed = time(0); 
    srand(seed); 
    num1 = 1 +rand() % 4; 
    num2 = 1 +rand() % 4; 
// correctAnswer = (num1+num2); 


    cout << "This program is a tool for young kids to learn basic math.\n"; 
    cout << "Just press any key and the learning will commence!\n"; 

    system("CLS"); 

    add(num1, num2, "Addition", '+'); 
// addResults(num1+num2); 

    return 0; 
} 

void add(int num1, int num2, string operation, char symbol) 
{ 
    cout << down8; 
    cout << over3 << operation << endl; 
    cout << over3 << "________\n"; 
    cout << over3 << setw(3) << num1 << endl; 
    cout << over3 << symbol << endl; 
    cout << over3 << setw(3) << num2 << endl; 
    cout << over3 << "________\n"; 


} 

답변

1

당신의 add 방법의 반환 유형 선언 (int)과 정의 (void)에 차이가 있습니다. 정의의 형식을 int으로 변경하고 결과를 반환해야한다고 생각합니다.

1

나는 완전히 확신 할 수는 없지만 문제는 처음부터 생각합니다. add 함수를 정의 할 때는 int add(int,int,string,char); 으로 작성하지만 실제로 함수를 작성할 때처럼 변수를 제대로 정의하지는 마십시오. 또한 처음에는 int로 정의하지만 void로 작성합니다. 컴파일러는 int 유형과 또 다른 void 함수 중 하나 인 추가 함수가 있다고 생각하기 때문에 무엇을 하려는지 알지 못합니다. [5] [Error] 오래된 선언을 모호하게합니다. int add (int, int, std :: string, char) '