Write a program to help me compute the sum. Your program should prompt me to enter numbers until I’m done (when I’m done I’ll enter -1). Then your program should print out the sum.
#include<iostream>
using namespace std;
int main()
{
double sum;
double number;
double total;
while (number !=-1)
{
cout<<"Input numbers: "<<endl;
cin>>number;
total+=number;
}
sum = total + number;
cout<<"The sum is "<<sum<<endl;
return 0;
}
For example I enter 9 and 9 then -1 I get 25. Would I just make double total =2; it works but don't really understand why it outputs 25. What is wrong in my code? I just started learning appreciate the help.