질문하기 전에이 문제를 검색 한 결과 모든 사람이 기능에 .h 파일을 사용하고있는 반면 선생님은 주 파일과 기능을 하나의 파일에 포함하도록 가르쳤습니다.
왜 그것이 정의되지 않았는지 알아 내고 싶습니다. 이 코드에 다른 문제가 숨어있을 수 있다는 것을 이해하지만 실제로 내가 뭘 잘못하고 있는지 파악할 수 없습니다.
내 코드는 다음과 같습니다.
#include <iostream>
#include <iomanip>
using namespace std;
void start();
void process();
void check();
void deposit();
const float dserv = 0.10;
const float cserv = 0.15;
const float fiveserv = 5.0;
const float oserv = 10.0;
int main()
{
float balance;
float amount;
bool fivehun;
bool endcheck;
float servcharge;
float servchargetotal;
char type;
start();
while(endcheck != true)
{process();}
cout<<"Current balance: $"<<balance<<endl;
cout<<"Total service charges: $"<<servchargetotal<<endl;
cout<<"Final balance: $"<<
system("pause");
return 0;
}
void start(float balance)
{
balance = 0;
cout<<fixed<<showpoint<<setprecision(2);
cout<<"Transactions will take the form of a letter followed by a dollar ";
cout<<"amount. Valid letters are “C” for a check, “D” for a deposit, and";
cout<<"“E” for the ending transaction (use zero on this transaction).";
cout<<"Press <Enter> after each line of input";
cout<<"Enter the beginning balance:"<<endl;
cin>>balance;
}
void process(float balance, float amount, char type, bool endcheck)
{
cout<<"Enter a transaction:"<<endl;
cin>>type>>amount;
if (type = "C"||"c")
{check();
endcheck = false;}
else if(type = "D"||"d")
{deposit();
endcheck = false;}
else if(type= "E"||"e")
{endcheck = true;}
}
void check(float balance, float amount, bool fivehun, float servcharge, float& servchargetotal)
{
balance = balance - amount;
servcharge = cserv;
if (balance<500.00)
{fivehun = true;}
else
{fivehun = false;}
cout<<"Transaction: Check in amount of $"<<amount<<endl;
cout<<"Current balance: $"<<balance<<endl;
cout<<"Service charge: Check - $"<<cserv<<endl;
if (fivehun == true)
{cout<<"Service charge: Below $500 - $"<<fiveserv<<endl;
servcharge = (fiveserv+servcharge);}
cout<<"Total service charges: $"<<servcharge<<endl;
servchargetotal = servchargetotal + servcharge;
}
void deposit(float balance, float amount, bool fivehun, float servcharge, float& servchargetotal)
{
balance = balance + amount;
servcharge = dserv;
if (balance<500.00)
{fivehun = true;}
else
{fivehun = false;}
cout<<"Transaction: Deposit in amount of $"<<amount<<endl;
cout<<"Current balance: $"<<balance<<endl;
cout<<"Service charge: Check - $"<<cserv<<endl;
if (fivehun == true)
{cout<<"Service charge: Below $500 - $"<<fiveserv<<endl;
servcharge = (fiveserv+cserv);}
cout<<"Total service charges: $"<<servcharge<<endl;
servchargetotal = servchargetotal + servcharge;
}
내가 정교하게 할 수있는 곳이 있다면 내가 할 수있는 모든 것을 수정 / 댓글을 달려고 노력할 것입니다.
start
MM이 말한 대로 기능을 확인하십시오. 다음과 같은 결과가 나타납니다.
float start() {
// ...
float balance;
cin >> balance;
return balance;
}
int main() {
float n;
n = start();
// ...
return 0;
}
그리고 다음 process
함수에 문제가 있으므로 모든 함수를 단계별로 확인하십시오 . if 문은 if (type == "C" || type == "c")
할당 대신 비교 연산자 여야합니다 type = "C"||"c"
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다