Need help with short program
Hello. In this short program I am calculating the amount of money a person spent paying a product off over x months.
Code:
#include<iostream>
using namespace std;
int main()
{
double amount, totalPay;
int num, months;
cout << "Enter how many months it took you to pay off the product: ";
cin >> months;
for(num = 1; num <= months; num++)
{
cout << "\nMonth " << num << ": \n" << "\tHow much did you pay? $";
cin >> amount;
totalPay = amount * num;
}
cout << "\nYou payed $" << totalPay << "\n" << endl;
return 0;
}
The problem I am having is I don't know how to calculate the amount payed over the x months. Like for an example, if the user enters 3 months how do I get the amount payed for all of those 3 months. With my code right now I am only getting the amount for the last month, and not all 3. No matter what number I enter for months, I only get the last month's amount.