#include <iostream>

#include <string>

using namespace std;



int currentmoney;

int itemnumber;

string str;



void buyitem(int& select) {


if (select == 1) {

currentmoney = currentmoney - 2000;

str = "활";

}

else if (select == 2) {

currentmoney = currentmoney - 800000;

str = "노트북";

}

else if (select == 3) {

currentmoney = currentmoney - 700000;

str = "아이폰";

}

else if (select == 4) {

currentmoney = currentmoney - 300000;

str = "에어팟";

}

else if (select == 5) {

currentmoney = currentmoney - 600000;

str = "아이패드";

}

if (currentmoney < 0) {

cout << "잔액이 부족합니다.";

}


if (currentmoney >= 0) {

cout << "남은잔액:" << currentmoney << "원" << endl;

cout << str << "을 구매하셨습니다." << endl;

}



}


int main() {

cout << "현재 가지고 있는 돈을 입력하십시오.";

cin >> currentmoney;


while (true) {

cout << "=================" << endl;

cout << "==철수네 상점" << endl;

cout << "=================" << endl;

cout << "1.활(2000원)" << endl << "2.노트북(800,000원)" << endl << "3. iPhone(700,000원)" << endl << "4.Airpods(300,000원)" << endl << "5.iPad(600,000원)" << endl << "10.종료" << endl;



cout << "구매하실 물품을 선택하십시오.";

cin >> itemnumber;



if (itemnumber == 10) {

break;

}


buyitem(itemnumber);


//buyitem(itemnumber);


//buyitem(itemnumber); 쓸때와 cout<< buyitem(itemnumber); 쓸때 다름. 후자로 하면 에러남. 


}

}



위 내용은 코드 내용입니다. 보시면 아시겠다시피...  cout << buyitem(itemnumber)를 쓰려고 하면 E0349 에러와 함께 이러한 피연산자와 일치하는 "<<" 연산자가 없습니다. 이렇게 메시지가 출력됩니다. 되게 하려고 어제 새벽 내내 씨름하다가 cout << 지우고 buyitem 함수만 남기니까 성공적으로 디버깅이 되었구요...


근데 왜 cout << buyitem(itemnumber)하면 안되고 그냥 buyitem(itemnumber) 만 하면 되는 걸까요.. 둘의 차이가 뭐길래 한쪽은 디버깅이 안되는 에러가 나는지 공부중인데 도저히 모르겠어서 여기에 질문글 올립니다...