Totalni sam pocetnik u svetu programiranja. Poceo sam da ucim c++ iz knjige "Learn to program C++" i sve je bilo ok dok nisam naisao na deo koda koji kod mene ne radi, a po knjizi bi trebao da radi. Pretpostavljam da je neki banalan razlog i zamolio bih nekog da mi objasni sta nije u redu.
Problem je u tome sto nakon pokretanja programa i upisa "yes", umesto mogucnosti da odaberem jednu od tri opcije, program prestaje da radi.
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
char response[256];
string moreBankingBusiness;
cout << "Do you want to do some banking? ";
cin >> moreBankingBusiness;
for (int i = 0; i < moreBankingBusiness.length(); i++)
{
moreBankingBusiness[i] = toupper (moreBankingBusiness[i]);
}
while (moreBankingBusiness == "YES")
{
cout << "What would you like to do? " << "(1=Deposit, 2=Withdraw, 3=Get Balance): ";
cin.getline(response,256);
if (atoi(response) < 1) | (atoi(response) > 3)
{
cout << response << endl << " - is not a valid banking function " << endl << endl;
return 1;
}
else
if (atoi(response) == 1)
{
cout << "You pressed 1";
}
if (atoi(response) == 2)
{
cout << "You pressed 2";
}
if (atoi(response) == 3)
{
cout << "You pressed 3";
}
}
cout << endl << endl << "Thanks for banking with us! ";
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main()
{
char response[256];
string moreBankingBusiness;
cout << "Do you want to do some banking? ";
cin >> moreBankingBusiness;
for (int i = 0; i < moreBankingBusiness.length(); i++)
{
moreBankingBusiness[i] = toupper (moreBankingBusiness[i]);
}
while (moreBankingBusiness == "YES")
{
cout << "What would you like to do? " << "(1=Deposit, 2=Withdraw, 3=Get Balance): ";
cin.getline(response,256);
if (atoi(response) < 1) | (atoi(response) > 3)
{
cout << response << endl << " - is not a valid banking function " << endl << endl;
return 1;
}
else
if (atoi(response) == 1)
{
cout << "You pressed 1";
}
if (atoi(response) == 2)
{
cout << "You pressed 2";
}
if (atoi(response) == 3)
{
cout << "You pressed 3";
}
}
cout << endl << endl << "Thanks for banking with us! ";
return 0;
}