C++ while loops on my program

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

int main()
{
    double Donor = 0.0;
    int totalRaised = 0;

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

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

    system("pause");
    return 0;
}

This is my code and my goal is to have the user put the input in and when done enter in -1 and display the total amount enter from the user but my problem when I run this code I do not get the correct value. Could someone point me in the right direction and explain how to make the program run correctly. Thank you.

Answers


while (Donor != -1)
    {
        cout << "Enter amount donated by next donor [or -1 to stop]:" << endl;
        totalRaised = totalRaised + Donor;
        cin >> Donor;
    }

see if it works.

you have to add the first input which was before the while loop and then go for the next input


Need Your Help

How to detect a mouse condition on Unix

c++ unix mouse

currently am working on some sort of dynamic loading library plugins development. The plugin will be loaded by other application. The programming language is C++.

Update timezone columns in a Postgres DB

postgresql timezone timestamp

I have started creating a product database using timestamp without timezone. Then, realizing my error, I started using timestamp with timezone. Now I'd like to unify this to the latter.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.