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
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2695166 | do while 문 어떤것이잘못된건지 모르겠어요 (2) | 아이폰 | 2025-05-18 |
2695122 | 구조체에 대해 물어보고 싶은게 있습니다 ^^^.. (7) | 수련 | 2025-05-17 |
2695091 | txt 파일 입출력 후 2차 배열에 저장하기입니다. (3) | 헛장사 | 2025-05-17 |
2695063 | 수도요금 프로그램좀 짜주세요. | 시내 | 2025-05-17 |
2695033 | 답변좀요ㅠㅠ (1) | 비사벌 | 2025-05-16 |
2695010 | C++의 STL은 왜 굳이 템플릿화 시켜서 라이브러리를 만드나요? (초보수준의 질문..) (2) | 엘보어 | 2025-05-16 |
2694958 | 로직이 변한다는 것에 대해서 궁금합니다. | 튼동 | 2025-05-16 |
2694929 | 열혈강의 25-2 두번째 문제 질문 | 지우개 | 2025-05-15 |
2694900 | dequeue 에서 리턴값 프린트 방법알려주세요 오늘 12시까지 대화방에 있습니다 도와주세요 | 미투리 | 2025-05-15 |
2694854 | 절대값을 구할때 (2) | 그녀는귀여웠다 | 2025-05-15 |
2694827 | 이제 어떻게 공부해야할지 모르겠네요 | 새얀 | 2025-05-14 |
2694778 | 순열 계산요. | 맛조이 | 2025-05-14 |
2694754 | ShowWindow 함수를 이용하려 하는데 질문있습니다. (2) | 파도 | 2025-05-14 |
2694731 | 리눅스 커널의 시작점 질문 | 미르 | 2025-05-13 |
2694702 | 이거 뭐가문제인가요 코드수정좀 (3) | 맑은 | 2025-05-13 |
2694675 | C언어 후위표기를 중위표기로 | 앨런 | 2025-05-13 |
2694646 | 안녕하세요 파일 합치기 함수! (1) | 연블루 | 2025-05-13 |
2694618 | 잘몰라서 설명부탁드립니다. scanf 관련 (3) | 파라 | 2025-05-12 |
2694590 | 이 코드가 뭐하는 코드일까요? #2 | 빵순 | 2025-05-12 |
2694559 | 동적할당으로 배열(2차원열)을 만드는데 있어 그걸 함수화시키는데... (1) | 늘솔길 | 2025-05-12 |