2014-07-14 3 views
-2

저는 C++의 초보자입니다.이 계산기는 간단한 계산기를 가지고 있지만 약간의 오류가있었습니다.C++에서이 오류를 어떻게 처리해야합니까?

  1. 이 오류 : 라인 'int' from 플로트 68 (복사 = operand1)을 변환하는 [경고].
  2. 이 하나를 함수에서`INT 주() :

어떻게 이러한 오류를 해결할 수 있습니까? 사전에 도와 주셔서 감사합니다.

E :

#include <iostream> 
#include <iomanip> 
using namespace std; 

struct Node{ 
    float number; 
    Node *next; 
}; 

Node* push(Node *stack, float data){ 
    Node *utility; 
    utility = new Node; 
    utility -> number = data; 
    utility -> next = stack; 
    return utility; 
} 

Node* pop(Node *stack, float &data){ 
    Node *temp; 
    if (stack != NULL){ 
    temp = stack; 
    data = stack -> number; 
    stack = stack -> next; 
    delete temp; 
    } 
    else cout << "\nERROR: Empty stack.\n"; 
    return stack; 
} 

int main() 
{ 
    float answer=0.f, operand1=0.f, operand2=0.f; 
    char ch = ' '; 
    int neg=0,cont=0,copy; 
    Node *utility, *top; 

    utility = new Node; 
    utility -> number = 0.f; 
    utility -> next = NULL; 
    top = new Node; 
    top -> number = 0.f; 
    top -> next = utility; 

    cout << "Enter the postfix operation: "; 
while(ch != '\n') 
    { 
     cin >> noskipws >> ch; 
     cont++;  
     if(cont<4&&ch=='-'){ 
       neg=-1; 
       ch=' '; 
     } 
     int operand = 0; 
     while(ch == ' '){ 
      cin >> ch; 
     }  
     if((ch >= '0')&&(ch <= '9')){ 
      while(ch != ' '){ 
      operand = operand*10 + (ch-48); 
      cin >> ch; 
      if(neg==-1 && operand1>=0){ 
       operand=operand * neg; 
      } 
      } 
      neg=0; 
      top = push(top, operand); 
     }else{ 
      ****copy=operand1;**** 
      top=pop(top, operand1); 
      top=pop(top, operand2); 
      if(operand2<0&&copy>0){ 
       operand2*=-1; 
       if(cont>4) 
        operand2*=-1; 
      } 
      switch(ch){ 
      case '+': answer = operand2 + operand1;break; 
      case '-': answer = operand2 - operand1;break; 
      case '*': answer = operand2 * operand1;break; 
      case '/': answer = operand2/operand1;break; 
      } 
      top=push(top, answer); 
     } 
    } 
    pop(top, answer); 
    cout << "Answer: " << answer << endl; 
    system("pause"); 
    return 0; 
} 
+0

'copy'를'int' 대신'float'으로 변경하십시오. 또한, 'float copy = operand1;'이라는 코드가 적용된 곳에서 사용하는 것이 더 낫습니다. –

+1

오류 또는 경고에 대한 질문을 게시 할 때 완전하고 * 수정되지 않은 * 오류/경고 로그를 포함하십시오. 질문을 수정하여 포함 시키십시오. 또한 문제의 원인을 * 표시합니다. 관련없는 코드가 막 방금 있기 때문에 [* Minimal *, Complete 및 Verifiable 예제] (http://stackoverflow.com/help/mcve)도 만들어야합니다. –

+0

오류가 없습니다. 한 가지 경고가 있습니다. 나열된 첫 번째 "오류"는 경고 자체이며 두 번째 경고는 해당 경고에 대한 정보입니다. –

답변

0

는 불쾌감을 줄 라인 (68)이고, 이것은 GCC 4.9.0의 출력 \ Test.cpp에 'INT 주() 함수에서 :

E : \ test.cpp : 68 : 15 : error : 잘못된 유형 인수 단 하나 '*' ('int'포함) **** copy = operand1; ****

E : \ test.cpp : 68:31 : 오류 : '연산자 *'에 일치하는 항목이 없습니다 (피연산자 유형이 '노드'임). **** copy = operand1; ****

****

**** 복사본 = operand1 :

오류는 단일 작업자 *가

선 68 (INT 대한 단일 운영자 *가 이진 없다) int로 적용 할 수 없었던

시작과 끝의 줄에있는 4 개의 *는 제거 된 문제입니다.

관련 문제