Assistance with homework

I need assistance with a problem. I have completed the C++ coding, however the formula I used is not giving me the correct answers. I need to write a C++ program for A classical music radio station that is currently raising funds. Listeners call in to make a donation to support them. Write a program to do the following. Ask the user to enter the amount of money donated by each donor. When there is no more to enter, type -1 to stop. Calculate and display the total amount of money raised.


#include <cstdlib>
#include <iostream>
using namespace std;

int main()
{
double donation = 0.0;
double totalAmt = 0.0;
double total = 0.0;


cout << "Enter amount donated by donor [or -1 to stop]: " ;
cin >> donation;

while (donation != -1)
{
totalAmt = donation + donation;
cout << "Total amount: " << totalAmt << endl;
total = totalAmt + totalAmt;
cout << "Enter amount donated by donor [or -1 to stop]: " ;
cin >> donation;
}
cout << "Total amount of money raised: " << total << endl;

system("pause");
return 0;
}
while (donation != -1)
{
totalAmt = donation + donation;
cout << "Total amount: " << totalAmt << endl;
total = totalAmt + totalAmt;
cout << "Enter amount donated by donor [or -1 to stop]: " ;
cin >> donation;
}


try this:
while (donation != -1)
{
total += donation;

cout << "Total amount: " << total << endl;
cout << "Enter amount donated by donor [or -1 to stop]: " ;
cin >> donation;
}
while (donation != -1)
{
cout << "Total amount: " << donation << endl;
cout << "Enter amount donated by donor [or -1 to stop]: " ;
totalAmt += donation ;
total += totalAmt;
cin >> donation;
}
cout << "Total amount of money raised: " << total << endl;
Thanks everyone for your assistance, I greatly appreciate it.
Topic archived. No new replies allowed.