Я создаю программное обеспечение в циклах C++ для одной функции (двойной) на неопределенный срок. Пройдя цикл в первый раз, второй раз, когда он запускается, он возвращает «nan». Где я неправ.Функция, возвращающая NaN в C++
int main()
{
double Balance = 100;
for (int i = 0; i < 5; i++) {
nyaradzo(Balance, i);
}
}
double nyaradzo(double bal, int pass)
{
int x = bal;
double Amount;
string policy_number;
double confirmation;
cout<<"WELCOME TO NYARADZO ONLINE POLICY PAYMENT"<<endl;
cout<<"ENTER YOUR POLICY NUMBER"<<endl;
cin>>policy_number;
cout<<"ENTER AMOUNT YOU WISH TO PAY FOR YOU POLICY"<<endl;
cin>>Amount;
cout<<"YOUR POLICY NUMBER IS: "<<policy_number<<endl;
cout<<"YOU HAVE CHOSEN TO PAY $"<<Amount<<" FOR YOUR FUNERAL POLICY. \n Is this information correct?"<<endl;
cout<<"1 TO CONFIRM"<<endl;
cout<<"2 TO CANCEL"<<endl;
cin>>confirmation;
if (confirmation==1) {
if (Amount <= x) {
x -= Amount;
cout<<"Transaction Complete"<<endl;
cout<<"YOUR BALANCE IS $"<<x<<endl;
return x;
}
else if (Amount > x) {
cout<<"TRANSACTION DENIED \a"<<endl;
cout<<"You cannot withdraw more than your actual balance..."<<endl;
return 0;
}
else {
cout <<x << endl;
cout<<"TRANSACTION DENIED \a"<<endl;
cout<<"Your purchase must be greater than or at least equal to $1"<<endl;
return 0;
}
}
else if (confirmation==2) {
cout<<"YOU HAVE CHOSEN TO CANCEL YOUR ZESA TRANSACTION"<<endl;
// transaction(bal, pass);
}
else
{
cout << "Invalid selection" << endl;
return 0;
}
}
Когда он проходит через цикл во второй раз, он терпит неудачу.
'двойное подтверждение;' должно быть 'int confirm ;'. –
Что «возвращает» NaN? У вас нет «возвращения здесь. –
@LightnessRacesinOrbit не является 'return's. Существует 'return', когда' confirm == 1 && Amount <= x' – MikeCAT