-2
저는 C++의 초보자입니다.이 계산기는 간단한 계산기를 가지고 있지만 약간의 오류가있었습니다.C++에서이 오류를 어떻게 처리해야합니까?
- 이 오류 : 라인 '
int' from
플로트 68 (복사 = operand1)을 변환하는 [경고]. - 이 하나를 함수에서`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&©>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;
}
'copy'를'int' 대신'float'으로 변경하십시오. 또한, 'float copy = operand1;'이라는 코드가 적용된 곳에서 사용하는 것이 더 낫습니다. –
오류 또는 경고에 대한 질문을 게시 할 때 완전하고 * 수정되지 않은 * 오류/경고 로그를 포함하십시오. 질문을 수정하여 포함 시키십시오. 또한 문제의 원인을 * 표시합니다. 관련없는 코드가 막 방금 있기 때문에 [* Minimal *, Complete 및 Verifiable 예제] (http://stackoverflow.com/help/mcve)도 만들어야합니다. –
오류가 없습니다. 한 가지 경고가 있습니다. 나열된 첫 번째 "오류"는 경고 자체이며 두 번째 경고는 해당 경고에 대한 정보입니다. –