#include <iostream>
usingnamespace std;
int main()
{
double monthOne, monthTwo, monthThree, monthFour, monthFive, monthSix, monthSeven, monthEight, monthNine, monthTen, monthEleven, monthTwelve, total, average;
cout << "This program will give you the total spent and the monthly average cost of your water bills for the last year.\n";
cout << "Enter the cost of your water bill from Month 1.\n";
cin >> monthOne;
cout << "Enter the cost of your water bill from Month 2.\n";
cin >> monthTwo;
cout << "Enter the cost of your water bill from Month 3.\n";
cin >> monthThree;
cout << "Enter the cost of your water bill from Month 4.\n";
cin >> monthFour;
cout << "Enter the cost of your water bill from Month 5.\n";
cin >> monthFive;
cout << "Enter the cost of your water bill from Month 6.\n";
cin >> monthSix;
cout << "Enter the cost of your water bill from Month 7.\n";
cin >> monthSeven;
cout << "Enter the cost of your water bill from Month 8.\n";
cin >> monthEight;
cout << "Enter the cost of your water bill from Month 9.\n";
cin >> monthNine;
cout << "Enter the cost of your water bill from Month 10.\n";
cin >> monthTen;
cout << "Enter the cost of your water bill from Month 11.\n";
cin >> monthEleven;
cout << "Enter the cost of your water bill from Month 12.\n";
cin >> monthTwelve;
total = monthOne + monthTwo + monthThree + monthFour + monthFive + monthSix + monthSeven + monthEight + monthNine + monthTen + monthEleven + monthTwelve;
average = total / 12;
cout << "The total spent over the last year was: " << total << endl;
cout << "The average spent each month for the year was: " << average << endl;
return 0;
}
Not asking for full out answers, I just need a push in the right direction.
I tried double month for the variable [12]= months. I might be way off, but any help would be awesome. Thanks.
#include <iostream>
usingnamespace std;
int main()
{
double cost, total;
for ( int m = 1; m <= 12; m++ )
{
cout << "Enter the cost of your water bill from month " << m << ": ";
cin >> cost;
total += cost;
}
cout << "The total spent over the last year was: " << total << '\n';
cout << "The average spent each month for the year was: " << total / 12 << '\n';
}
Oh man, I think you gave me the whole answer haha. I was looking for tips on how to do it. Thank you though.
I was trying something new and wanted to see how would I be able to do this. I saw on a site that you can do array with double.
Enter your water bill cost for January: 12.5
Enter your water bill cost for February: 8.79
Enter your water bill cost for March: 15.5
Enter your water bill cost for April: 10
Enter your water bill cost for May: 16.8
Enter your water bill cost for June: 35.88
Enter your water bill cost for July: 45
Enter your water bill cost for August: 25
Enter your water bill cost for September: 18
Enter your water bill cost for October: 9
Enter your water bill cost for November: 15
Enter your water bill cost for December: 15
Total water bill: 226.47
Average payment: 18.8725
Sometimes it is easier to just throw out a full code example than do piece-meal hints.
Using an array (or a C++ standard library container such as std::vector) for something this simple can be a bit of over-kill, as lastchance said.
If'n you wanted to use std::vector instead of regular arrays #include <vector>; and change the two arrays to use vectors: