I'll help you on the way you're going, but there are several things you'd better do differently. One of the changes is that I would probably pass the argument by reference instead of making a return
, but probably not yet learned to use it, so it goes in the simplest way.
#include <iostream>
#include <locale.h>
using namespace std;
int getnegativo(int a, int b);
int main() {
setlocale(LC_ALL, "portuguese");
int cont, cot = 0;
do {
cout << "digite um valor: ";
cin >> cont;
cot = getnegativo(cont, cot);
} while (cont != -1);
cout << "número de valores negativos digitados: " << cot;
cout << endl << endl;
return 0;
}
int getnegativo(int a, int b){
if (a < 0)
b++;
return b;
}
See running on ideone .
I would start thinking about what you are using. Why use locale
in every application, if it has no function in the code? It's still worse because it's something of C and not native to C ++.