I have a header called "counter.h":
#ifndef REMAINDER_COUNTER_H
#define REMAINDER_COUNTER_H
extern int count;
int read();
int increment();
int decrement();
#endif //REMAINDER_COUNTER_H
the c++ file called counter.cpp:
int count;
int read(){
return count;
}
int increment(){
if (count < 5)
count++;
return count;
}
int decrement(){
if (count > 0)
count--;
return count;
}
and the main file called "mainxc.cpp":
#include <iostream>
#include "counter.h"
int main(){
count = 2;
for (int i = count; i <= 6; i+=2)
increment();
std::cout << read();
}
I am trying to get 6 by only using the function read() 3 times but it does not print 6 but 5. Why is that?
Here is an example of a class :