archimed7592, спасибо =)
вот ещё одну написал, но думаю и её можно упростить:
| Код | int main() { int pound1,shilling1, pence1,pound2,shilling2,pence2; char q; do { cout << "Input first amount:"; cin >> pound1 >> q >> shilling1 >> q >> pence1 ; cout << "Input second amount:"; cin >> pound2 >> q >> shilling2 >> q >> pence2; pound1 +=pound2; shilling1 += shilling2; pence1 += pence2;
if(pence1 > 11) { if(pence1%12 == 0) { shilling1 = (pence1/12) + shilling1; pence1 = pence1 - (pence1/12)*12; } else { shilling1 = pence1%12 + shilling1; pence1 = pence1 - (pence1%12)*12; } } if(shilling1 > 19) { pound1 = shilling1%20 + pound1; shilling1 = shilling1 - (shilling1%20)*20; } cout << endl << "Total: " << pound1 << '.' << shilling1 << '.' << pence1 << endl; cout << "again?" << endl; cin >> q; }while(q!='n'); return 0; }
|
сложение двух сумм состоящих из фунтов, шиллингов и пенсов. |