Hello all..
I am currently making a mini-game, where the program will make a number, and the user will be able to enter the minimum and maximum of that number, and an amount of guesses..
I am having trouble with it though, and i was hoping you could help me.
Btw, don't mind the Printf's, it's all in danish ;-)
Edit: There is no problems when compiling, and in the beginning where i have to press a key to start is okay as well, but when i am prompted to enter the first number, i enter that, press enter and the error comes up. the cmd window just freezes, and i can't close it.. But i can stop debugging inside visual c++, and it will close..
My code is:
Code:
// Gæt et tal.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <conio.h>
#include <cstdlib>
#include <time.h>
int input (int min, int max, int maxgaet)
{
printf("\nIndtast det mindste tal: ");
scanf_s("%d", min);
printf("\n Indtast det hoejeste tal: ");
scanf_s("%d", max);
printf("\n Indtast max antal gaet: ");
scanf_s("%d", maxgaet);
return min, max, maxgaet;
}
int random (int min, int max)
{
int random_integer;
int range=(max-min)+1;
srand((unsigned)time(0));
for(int index=0; index<1; index++)
random_integer = min+int(range*rand()/(RAND_MAX + 1.0));
return random_integer;
}
int gaet (int random, char lav, char hoej, char rigtig)
{
int gaet;
gaet = '0';
printf("\nIndtast det tal du gaetter på: ");
scanf_s("%d", gaet);
if (gaet < random)
{
lav = '1';
rigtig = '0';
hoej = '0';
}
else if (gaet == random)
{
rigtig = '1';
hoej = '0';
lav = '0';
}
else if (gaet > random)
{
hoej = '1';
lav = '0';
rigtig = '0';
}
return random, lav, hoej, rigtig;
}
void resultat (int antal, int maxgaet)
{
if (antal*2 <= maxgaet)
printf("\nHip hip hurra! På kun %d forsoeg!", antal);
else if (antal <= maxgaet)
printf("\nTillykke, du gaettede det. Dog på %d forsoeg.\nPrøv igen, og se om du kan komme under halvdelen af tilladte gaet.");
else
printf("\nDesværre, du gættede det ikke indenfor dine tilladte gæt");
}
int _tmain(int argc, _TCHAR* argv[])
{
char start, lav, hoej, rigtig;
int min, max, maxgaet, antal,rando;
min = '0';
max ='0';
maxgaet ='0';
printf("\nTryk en tast for at starte");
start = _getch();
input(min, max, maxgaet);
random(min, max);
antal = lav = hoej = rigtig = rando = '0';
do
{
gaet(rando, lav, hoej, rigtig);
antal++;
}
while ((antal < maxgaet) || (rigtig == 0));
resultat(antal, maxgaet);
return 0;
}
and the error i get is this:
I hope someone can help me figure out what is wrong, since it makes no sense to me :-)