I want the variable “minne” to be counted upwards once ever time I run the function “multi” and then print it back on the screen in the main function.
This doesnt happen though, it is stuck on telling me I used the function “0” times over and over again. Why is that?
//Multi
#include <iostream>
//Deklarerar variablar
int a,b,x, minne;
//Deklarerar funktioner
int multi(int a, int b);
int main(void)
{
using std::cout;
using std::cin;
while(1 < 2)
{
cout << "Ge mig ett nummer som du vill multiplicera:\n";
cin >> a;
cout << "\n Och ett till tack: \n";
cin >> b;
multi(a,b);
cout << "\n Summan av dessa tal är: " << x << "\n";
cout << "You have called the function: " << minne << " times.\n";
}
return 0;
}
int multi(int a, int b)
{
x = a * b;
int minne = minne + 1;
return x, minne;
}
You’re hiding the global
minnewith your localint minne– get rid of theintand just writeminne = minne + 1, or even just++minne. Also, you don’t need to return anything from the function as you’re not using the result.