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
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2700368 | if에 관해서 질문이요... | Orange | 2025-07-04 |
2700339 | 이거 결과값이 왜이런건지.. (4) | 그댸와나 | 2025-07-04 |
2700313 | 파일 읽어서 저장하는데 빈파일일 경우 문재가 발생하네요.. (2) | 크나 | 2025-07-03 |
2700287 | 구조체 동적할당 연습을 하는데 오류가 뜹니다...(해결) (3) | 아련나래 | 2025-07-03 |
2700264 | 문자와 숫자 동시에 입력??? | 글고운 | 2025-07-03 |
2700236 | txt파일로만 쓰고 읽게 하려면 어떻게 해야 하나요..?? (8) | 미국녀 | 2025-07-03 |
2700211 | 전위 연산자 (2) | 어른처럼 | 2025-07-02 |
2700183 | C에서 파일이름을 받고, 그 파일의 사이즈를 출력해줘야하는데 내용이 출력이 안되네요 ;ㅅ; | 피스케스 | 2025-07-02 |
2700150 | 꼭좀 도와주세요ㅠㅠㅠ | 호습다 | 2025-07-02 |
2700095 | 연산문제...질문... | 오빤테앵겨 | 2025-07-01 |
2700070 | while문 , 3의배수 출력하는 프로그램좀 짜주세욤. | 횃불 | 2025-07-01 |
2700041 | 초보인데요 ㅎ 배열안에 배열을 집어넣을수 있나요?? | 헛장사 | 2025-07-01 |
2700012 | 배열// (1) | 전갈자리 | 2025-07-01 |
2699895 | 무한루프에 빠집니다.!! 해결좀부탁드려요 (10) | 선아 | 2025-06-30 |
2699842 | 질문을 너무 많이 하네여.....죄송.... (2) | 해님꽃 | 2025-06-29 |
2699816 | 오류 질문입니다.. (1) | 해비치 | 2025-06-29 |
2699763 | 질문입니다 ! 꼭 좀 도와주세요ㅠㅠ (2) | 미라 | 2025-06-28 |
2699555 | c언어 다항식을 입력을 했는데 왜 출력이 안될까요? | 피스케스 | 2025-06-27 |
2699528 | C언어 포인터연산 질문입니다. (3) | 안녕나야 | 2025-06-26 |
2699476 | 끌어올림;;달력 짜봤는데요 이 소스 줄일 수 있나요? - 스샷첨부 (2) | 클라우드 | 2025-06-26 |