c++질문드립니다 ㅠㅠ
찬놀
용돈 관리 프로그램 만들고있습니다 아주단순한거.
근데 수입입력하고 월 요약할때 계속 금액이 이상하게 증가되는 현상이 생깁니다.
어떤루프를 돌려야 할지.. 아니면 아에 새로 짜야 하는건지.. 궁금합니다
예 ) 처음에 수입을 2000원 입력 받고4번 눌러서 처음 누르면 2000원이 뜹니당. 하지만 다시 4번을 누르게되면 2000원이 더 증가 된 4000원이 되구요 .. ㅠㅠ 제가 생각하는 알고리즘은 이건데 .. ㅠㅠ 덧셈 해주는 과정에서 계속 증가 되는부분이 있는데 해결방법좀 찾아주세용.ㅠㅠ
#include iostream
#include fstream
using namespace std;
#define QUIT -999
class Allowance{
private:
int income;
int spending;
int food_spending;
int book_spending;
int charge_spending;
int etc_spending;
int year, month, day; // 날짜변수
public:
Allowance(){
income = 0;
food_spending=0;
book_spending=0;
charge_spending=0;
etc_spending=0;
}
void inputToday(){
cout 오늘의날짜를 입력하세요 : ;
scanf(%d.%d.%d, &year , &month, &day);
}
void inputIncome(){
int money = 0;
cout 수입금액 : ; cin money;
income = money;
cout money endl;
}
void inputSpending(){
cout 식비 : ; cin food_spending;
cout 통신비 : ;cin charge_spending;
cout 책 : ; cin book_spending;
cout 기타 : ; cin etc_spending;
}
int getIncome(){
return income;
}
int getFood_spending(){
return food_spending;
}
int getBook_spending(){
return book_spending;
}
int getCharge_spending(){
return charge_spending;
}
int getEtc_spending(){
return etc_spending;
}
int getYear()
{
return year;
}
int getMonth()
{
return month;
}
int getDay()
{
return day;
}
};
int main()
{
int selectNum; // 메뉴선택 번호 변수
int inputMonth; //요약 월 입력 변수
int summaryIncome=0; //월요약 수입 변수
int summarySpending=0; //월요약 수입 변수
int allSpendingF_item=0; //지출항목별 총액(식비)
int allSpendingB_item=0; //지출항목별 총액(책)
int allSpendingC_item=0; //지출항목별 총액(통신요금)
int allSpendingE_item=0; //지출항목별 총액(기타)
Allowance money[10];
int i=0;
while(1){
cout 1. 오늘의 날짜 입력endl;
cout 2. 용돈 수입 입력endl;
cout 3. 지출 항목과 액수 입력endl;
cout 4. 월 요약 출력endl;
cout 5. 지출항목별 지출총액 출력 endl;
cout 6. 일일 수입/지출 내역 출력endl;
cout 7. 저장endl;
cout 번호 선택 -; cin selectNum;
if(selectNum == QUIT) //종료 함수
break;
switch(selectNum)
{
case 1:
money[i].inputToday();
break;
case 2:
money[i].inputIncome();
break;
case 3:
money[i].inputSpending();
break;
case 4:
cout월을 입력하세요 : ; cin inputMonth;
for(int j=0; j=i; j++)
{
if(inputMonth == money[j].getMonth())
{
summaryIncome = summaryIncome + money[j].getIncome();
summarySpending += money[j].getFood_spending() + money[j].getBook_spending() + money[j].getCharge_spending() + money[j].getEtc_spending();
break;
}//if 월비교후
}
cout inputMonth월 요약endl수입 : summaryIncome endl 지출 : summarySpendingendl
잔액 : summaryIncome-summarySpendingendl; //출력
break;
case 5:
for(int j=0; j=i; j++)
{
allSpendingF_item += money[j].getFood_spending();
allSpendingB_item += money[j].getBook_spending();
allSpendingC_item += money[j].getCharge_spending();
allSpendingE_item += money[j].getEtc_spending();
}
cout 지출항목별 총액endl;
cout 식비 : allSpendingF_itemendl;
cout 책값 : allSpendingB_itemendl;
cout 요금 : allSpendingC_itemendl;
cout 기타 : allSpendingE_itemendl;
cout endl;
break;
case 6:
for(int j=0; j=i; j++)
{
cout money[j].getYear().money[j].getMonth() .money[j].getDay() ;
cout money[j].getIncome() money[j].getFood_spending() money[j].getBook_spending()
money[j].getCharge_spending() money[j].getEtc_spending();
cout 잔고endl;
}
break;
case 7:
i++;//저장
ofstream fout(input.txt);
for(int j=0; ji; j++)
{
fout money[j].getYear().money[j].getMonth() .money[j].getDay() ;
fout money[j].getIncome() money[j].getFood_spending() money[j].getBook_spending()
money[j].getCharge_spending() money[j].getEtc_spending();
fout 잔고endl;
}
fout.close();
break;
}//switch
}//while
}