#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
	float bs, shot, hit, s, t, wound, ap, save, final;
	
	/* Read the relevant statistics */

	printf("Please enter the BS of the model firing: ");
	scanf("%f", &bs);
	printf("Please enter the number of shots fired: ");
	scanf("%f", &shot);
	printf("Please enter the strength of the gun: ");
	scanf("%f", &s);
	printf("Please enter the toughness of the target: ");
	scanf("%f", &t);
	printf("Please enter the AP of the gun (if AP is - or does not apply, enter 7): ");
	scanf("%f", &ap);
	printf("Please enter the target's armour save: ");
	scanf("%f", &save);
	
	/* Calculate the average number of hits */
	
	if ( bs == 1 ) {hit = shot * 1/6;}
	if ( bs == 2 ) {hit = shot * 2/6;}
	if ( bs == 3 ) {hit = shot * 3/6;}
	if ( bs == 4 ) {hit = shot * 4/6;}
	if ( bs == 5 ) {hit = shot * 5/6;}
	if ( bs == 6 ) {hit = shot * 31/36;}
	if ( bs == 7 ) {hit = shot * 32/36;}
	if ( bs == 8 ) {hit = shot * 33/36;}
	if ( bs == 9 ) {hit = shot * 34/36;}
	if ( bs == 10 ) {hit = shot * 35/36;}
	
	/* Calculate the average number of wounds before armour saves */
	
	if ( s > t + 1 ) {wound = hit * 5/6;}
	if ( s == t + 1 ) {wound = hit * 4/6;}
	if ( s == t ) {wound = hit * 3/6;}
	if ( s == t - 1 ) {wound = hit * 2/6;}
	if ( s < t - 1 ) {wound = hit * 1/6;}

	/* Calculate the average number of wounds after armour saves */
	
	if ( ap <= save ) {final = wound * 1;}
	if ( ap > save && save == 2 ) {final = wound * 1/6;}
	if ( ap > save && save == 3 ) {final = wound * 2/6;}
	if ( ap > save && save == 4 ) {final = wound * 3/6;}
	if ( ap > save && save == 5 ) {final = wound * 4/6;}
	if ( ap > save && save == 6 ) {final = wound * 5/6;}
	
	/* Print the average number of wounds */

	printf("The defender will suffer an average of %f wounds.\n", final);
	
}