I am now in my first C++ class, and I am learning it fairly well, but it seems like the simplest programs are giving me the most trouble.
This program uses the function FindSum() , and tells the user to input positive integers (negative integer to quit), and then adds all of the positive integers together as one positive output sum. I know some of you guys are probably laughing at me right now, I know it is a simple program, but I just can't get it to output the correct numbers.
Here is what I have so far, please feel free to run it yourself and let me know what I am doing wrong. Thanks! Brent
#include <iostream>
using namespace std;
int FindSum(int, int);
int main ()
{
int a, b;
cout << "Enter a positive value (negative value to stop): ";
cin >> a;
b=FindSum(a,b);
cout << "Your numbers added is: "<<b<< endl;
return 0;
}
FindSum(int x, int y)
{ while (x > 0){
cin>>x;
y=x+y;}
return y ;
}