c언어 수정 좀 부탁드립니다
조회수 834회
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char str1[10];
char str2[10];
char str3[10];
int num1, res;
char *ps1 = str1;
char *ps2 = str2;
char *ps3 = str3;
while (1)
{
printf("0P #1: ");
scanf("%s", str1);
if (ps1[0] == '0')
{
return 0;
}
printf("OPER: ");
scanf("%s", str2);
printf("OP #2: ");
scanf("%s", str3);
if (str2[0] == '@' && str2[1] == '\0')
{
strcat(str1, str3);
num1 = atoi(str1);
res = num1 + 1;
printf("Result: %d\n", res);
}
else if (str2[0] == '#' && str2[1] == '\0')
{
strcat(str3, str1);
num1 = atoi(str3);
res = num1 - 1;
printf("result : %d\n", res);
}
else
return 0;
}
return 0;
}
위 문제에 맞춰 제가 코드를 짜보았는데요 틀린 부분이 있으면 말씀햊해시고 혹시 잘 짜실 수 있으면 ㅂㅜ탁드립니다
-
(•́ ✖ •̀)
알 수 없는 사용자 - 〉
1 답변
-
#include <iostream> using namespace std; int main(void) { int OP1, OP2; // 받는 변수 1, 2 char OPER; // 연산자 while (1) { cout << "0P #1: "; cin >> OP1; if (OP1 == 0) { break; } cout << endl << "OPER: "; cin >> OPER; cout << "OP #2: "; cin >> OP2; if (OPER == '@') { OP2 += 1; cout << OP1 << OP2 << endl; } else if (OPER == '#') { OP1 -= 1; cout << OP2 << OP1 << endl; } else { cout << "Wrong Operator!" << endl; main( ); } } return 0; }
도대체 뭘 원하시는 지 모르겠어서 제 나름대로 만들어 봤습니다. 이걸 원하시는게 맞다면 구지 Strcat과 atoi함수를 쓸 필요가 있나 싶네요..
댓글 입력