For loop executes but does not seem to be calculating correctly
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
Following code when executed does not appear to be calculating correctly? Any advise would be greatly appreciated.
#include <iostream>
#include <cstdlib>
using namespace std;
int main ()
{
int acctNum;
string firstName;
string lastName;
int purchasePrice;
int payment;
int count;
cout << "Please enter account number: " << endl;
cin >> acctNum;
cout << "Please enter customer's first name: " << endl;
cin >> firstName;
cout << "Please enter customer's last name: " << endl;
cin >> lastName;
cout << "Please enter purchase price: " << endl;
cin >> purchasePrice;
payment = purchasePrice / 12;
cout << "Customer First Name: " << firstName << endl;
cout << "Customer Last Name: " << lastName << endl;
cout << "Account Number: " << acctNum << endl;
for(count = 1; count <= 12; count++)
{
cout << "Payment Number" << count << " : $ " << payment << endl;
}
system("PAUSE");
return 0;
}
|
Last edited on
Hello,
Please use code tags when posting.
1 2 3 4
|
int purchasePrice;
int payment;
payment = purchasePrice / 12;
|
You are dividing an int by 12, you won't get any decimal places.
Try changing purchasePrice and payment to doubles.
Regards
Last edited on
Topic archived. No new replies allowed.