지금 나는 Stephen Kockan의 "Programming in C, 3rd edition"이라는 책을 읽고 c로 프로그래밍하는 법을 배우고 있습니다. 연습 문제 6-4는 정말 두통을 안겨줍니다. 이 책에서는 말한다 :연습 문제 6-4 프로그래밍 C
이Write a program that acts as a simple "printing" calculator.
The program should allow the user to type in expressions of the form
다음 operatros 프로그램에 의해 인식되어야한다 숫자 연산자 :
'+' '-' '*' '/' 'S' 'E'
의 S 운영자가 프로그램 "이 설정을 알려줍니다 누적 기 "를 입력 번호로 변경하십시오. E 연산자는 실행이 으로 끝나도록 프로그램에 알립니다. 산술 연산은 누적 기의 내용에 대해 수행 된 키 수는 seconcd 피연산자로 사용됩니다.
Here is a link 내가 어떻게 알아 냈는지.
불행히도 Objective-C에 있지만 (여전히 운동이 동일합니다!) 이해할 수 없습니다. Objective-C 구문.
UPDATE는
이것은 내가 지금까지 만든 것입니다 :
// "Printing" Calculator
#include <stdio.h>
int main(void)
{
char operator;
float value, result, accumulator;
printf("Begin Calculations...\n\n");
operator = '0';
while (operator != 'E')
{
scanf("%f %c", &value, &operator);
switch(operator)
{
case 'S':
accumulator = value;
printf("The accumulator = %f", accumulator);
break;
case '+':
result = accumulator + value;
printf("%f + %f = %f", accumulator, value, result);
break;
case '-':
break;
case '*':
break;
case '/':
break;
default:
printf("Unknown operator");
break;
}
}
printf("Calculations terminated");
return 0;
}
나는
scanf()
기능을 사용하고, 작업에 대한 값과 값 모두를 읽는 방법을 알아낼 수 없습니다
누산기. 그 두 가지가 같지 않을 수도 있기 때문입니다.
귀하의 질문은 ... – Joe
죄송합니다, 무슨 일입니까? – Nobilis
Objective C에서 순수 C 로의 변환을 기대하십니까? – AurA