c++ - How to make an array print zeros when there is no input in that slot -
the user inputs double , string gets stored 2 arrays. :
{ double doc; string nm; cout << " please enter amount charged credit card " << endl; cin >> doc; cout << " please enter charge made " << endl; cin >> nm; getline(cin, nm); cca.docharge(nm,doc); break; }
then double , string passed :
{ if (amount > 0) { (int = 9; != 0; i--) { last10withdraws[i] = last10withdraws[i-1]; last10charges[i] = last10charges[i-1]; } last10withdraws[0] = amount; last10charges[0] = name; setbalancew(amount); } else { cout << " error. number must greater zero. " << endl; } return 0; }
this seems work storing data arrays. use function display data inside of arrays :
{ cout << " account: creditcard withdraws " << " " << " account: creditcard deposits " << " " << " account: creditcard last 10 charges " << endl; cout << " " << last10withdraws[0] << " " << last10deposits[0] << " " << last10charges[0] << endl; cout << " " << last10withdraws[1] << " " << last10deposits[1] << " " << last10charges[1] << endl; cout << " " << last10withdraws[2] << " " << last10deposits[2] << " " << last10charges[2] << endl; cout << " " << last10withdraws[3] << " " << last10deposits[3] << " " << last10charges[3] << endl; cout << " " << last10withdraws[4] << " " << last10deposits[4] << " " << last10charges[4] << endl; cout << " " << last10withdraws[5] << " " << last10deposits[5] << " " << last10charges[5] << endl; cout << " " << last10withdraws[6] << " " << last10deposits[6] << " " << last10charges[6] << endl; cout << " " << last10withdraws[7] << " " << last10deposits[7] << " " << last10charges[7] << endl; cout << " " << last10withdraws[8] << " " << last10deposits[8] << " " << last10charges[8] << endl; cout << " " << last10withdraws[9] << " " << last10deposits[9] << " " << last10charges[9] << endl; cout << endl; }
lets user has inputted 3 doubles deposit array. when call function display :
60 30 20 -9.25596e+061 -9.25596e+061 -9.25596e+061 -9.25596e+061 -9.25596e+061 -9.25596e+061
how can make -9.25596e+061's 0's? have not been able find helping me. array contains strings, when called display displays nothing. why ?
initialize array as:
int last10withdraws[10] = {0};
now elements zero.
if user enters 3 numbers, first 3 elements non-zero (assuming non-zero allowed), , rest zero.
if last10withdraws
member of class m(and you're using c++03), can use member-initializer list default-initialize initialize elements zero.
class myclass { int last10withdraws[10]; public: myclass() : last10withdraws() { //^^^^^^^^^^^^^^^^^^^ member initializer list } };
hope helps.
Comments
Post a Comment