Heres some code i'm writing up at the mo. ive come across a funny little problem i can't get my head round. All i want to do is i want my 2 functions to keep hold of a value for me based on if it's higher or lower than (when i send other values to it)
#include <iostream>
#include <string>
#include <sstream>
#include <windows.h>
#include <mmsystem.h>
#include <stdlib.h>
#include <time.h>
usingnamespace std;
int hstik = 0;
int datik = 0;
int keeplowestdarts (int darts) { int lowestdarts; if (datik == 0) lowestdarts = 500; if (darts < lowestdarts) lowestdarts = darts; return lowestdarts; }
int keephighscore (int score) { int highscore; if (hstik == 0) highscore = 0; if (score > highscore) highscore = score; return highscore; }
int main ()
{
int scored;
int darts;
int gethighscore;
int getlowestdarts;
scored = 60;
keephighscore (scored);
hstik++;
darts = 9;
keeplowestdarts (darts);
datik++;
scored = 50;
keephighscore (scored);
darts = 15;
keeplowestdarts (darts);
getlowestdarts = keeplowestdarts (500);
gethighscore = keephighscore (0);
cout<<"\n\n "<<gethighscore<<" "<<scored<<" "<<getlowestdarts<<" "<<darts<<endl;
system("pause");
return 0;
}
I expected on screen " 60 50 9 15 ".
But instead i get " 15 50 15 15 ".
I can't find the wrong bit in the code and there are no compiling errors or warnings either..ide love someone to show me whats wrong here?
PS: The keephighscore function works fine on its own..its been doing this since i made the keeplowestdarts function...Oh, and please ignore the not needed header files.
I assume the problem is in lines 37, 31, 35, 38. They don't do anything. You need to assign the result to some variable. Otherwise the functions don't change anything.