In: Computer Science
in c++,
please provide only a function. the function should be named "tally." it takes no parameters but returns an int. the first int should be 0, next being 1, then 2, etc..
will rate if correct. again should only be 1 function.
#include <iostream>
using namespace std;
//function declaration
int tally();
int main()
{
cout<<"first call of tally function return value: "<<tally()<<endl;
cout<<"second call of tally function return value: "<<tally()<<endl;
cout<<"third call of tally function return value: "<<tally()<<endl;
cout<<"fourth call of tally function return value: "<<tally()<<endl;
}
//function definition
/*
Function name: tally
input: None
Output: returns integer
first call return 0, second call returns 1 and so on
*/
int tally()
{
static int ret=0;
return ret++;
}
==================================
//Output
first call of tally function return value: 0
second call of tally function return value: 1
third call of tally function return value: 2
fourth call of tally function return value: 3