int minus the amount of rand()
So this is the begging of a text-adventure game so all the text is just story line ( and a lot have been removed but no important part ).
But the problem is that i want "liv" ( life ) should be permanently changed after the attack.
printf("Du har %d i liv\n", liv-rand() % 4);
What i want to happen is that you get hit 5 times ( looped 5 times ) and hurt you a random amount between 0 -4 ( rand() % 4) ;
liv ( life ) is hundred from the start and then
you lose 3 health
you lose 2 health
you lose 1 health
you lose 2 health
you lose 2 health
You now have 90 liv ( life )
The code
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
char namn[20];
float svarhet;
int liv, pengar;
int forsta, vakt;
int i;
int menu;
printf("Välkomen till puzzlet\n");
printf("Vänligen skriv in din pesudonym\n"); //stava
scanf( "%s", namn);
printf("du valdet namnet %s\n\n", namn);
printf("välj svårighetsgrad 1 eller 2\n");
printf("1=svår\n");
printf("2=lätt\n");
scanf("%d", &menu );
switch( menu ) {
case 1: liv = 100; pengar = 1000; printf("du valde den svåra"); break;
case 2: liv = 200; pengar = 2000; printf("Du valde det lätta spåret, mes"); break;
default: printf("Invalid option selected\n");
}
printf("Låt oss börja leken\n");
printf("Info\n");
printf("#################\n");
printf("# Liv %d #\n", liv );
printf("# Pengar %d #\n", pengar );
printf("#################\n\n");
printf(" Liv %d Pengar %d \n", liv, pengar);
int max = 5;
int d = 0;
int t;
printf("skriv 1\n"); //stava
scanf( "%d", &t);
if (t == 1 )
srand ( time(NULL) );
for(d = 0; d < max;d++){
srand ( time(NULL) );
printf("Du har %d i liv\n", liv-rand() % 4);
printf("%d\n",d); // vilken loop vi är på
}
printf("\n\n\nDu har %d i liv\n", liv);
}
Hope someone got what i mean do Englis is far away from my native language.