Thread: My Program gives a load of errors on comile, can some1 help explain them to me please

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    10

    My Program gives a load of errors on comile, can some1 help explain them to me please

    here is my code.
    Code:
    #include <stdio.h>
    
    /* Info */
    /*
    Num - Name
    
    401 - Rocket Launcher
    402 - Light Laser
    403 - Heavy Laser
    404 - Gauss Cannon
    405 - Ion Canon
    406 - Plasma Turret
    407 - Small Shield Dome
    408 - Lage Shield Dome
    409 - Small Grav Dome
    410 - Large Grav Dome
    --
    502 - ABM
    503 - IPM
    
    */
    
    main()
    {
    	/* Defind the variables that will be used. */
    	int item[502],item[503],missiles;
    	int item[401],item[402],item[403],item[404],item[405],item[406],item[407],item[408],item[409],item[410];
    	int item[401][s],item[402][s],item[403][s],item[404][s],item[405][s],item[406][s],item[407][s],item[408][s],item[409][s],item[410][s];
    	int weapons_tech,id;
    	int randomDefense,selectionDefense;
    	char name[401],name[402],name[403],name[404],name[405],name[406],name[407],name[408],name[409],name[410];
    
    	/* First lets set the names */
    	name[401] = "Rocket Launcher";
    	name[402] = "Light Laser";
    	name[403] = "Heavy Laser";
    	name[404] = "Gauss Cannon";
    	name[405] = "Ion Canon";
    	name[406] = "Plasma Turret";
    	name[407] = "Small Shield Dome";
    	name[408] = "Lage Shield Dome";
    	name[409] = "Small Gravity Dome";
    	name[410] = "Large Gravity Dome";
    
    	/* Set the shield caps */
    	item[401][s] = 20;
            item[402][s] = 25;
            item[403][s] = 100;
            item[404][s] = 200;
            item[405][s] = 500;
            item[406][s] = 300;
            item[407][s] = 2000;
            item[408][s] = 10000;
            item[409][s] = 2000000;
            item[410][s] = 10000000;
    
    	/* Title */
    	printf("IPM Simulator for Darkness of Evolution\nBy Anthony (MadnessRed) - [http://madnessred.co.cc]\n\n");
    
    	/* How many IPMS? */
    	printf("How many IPMs are you firing?\n");
    	scanf("&#37;i", &item[503]);
    	/* How many ABMs? */
    	printf("\nHow many ABMs does you opponent have?\n");
    	scanf("%i", &item[502]);
    
    	/* Stage 1 - ABS are fired against IPMS */
    	item[503] = item[503] - item[502];
    	printf("\nEnter you weapon tech level.\n");
    	scanf("%i", &weapons_tech);
    
    	/* Are there any left? */
    	if (item[503] <= 0){
    		/* No there aren't */
    		printf("\nAll your IPMs have been destroyed. The defender still has %i ABMS\n",(1 - item[503]));
    		
    	}else{
    		/* Yes there are */
    		/* So there are 0 ABMS now. */
    		item[502] = 0;
    		printf("\nAfter facing the defenders ABS you have %i APMs left.\n",item[503]);
    		printf("\nNow you will need to enter the defenders stats.");
    
    		/* Now a loop for inserting each defence for opponent */
    		for ( id = 401; id < 411; id++ ) {
    			printf("\n%s: "name[id]);
    			scanf("%i", &item[id]);
    		}
    
    		/* lets work out new score. */
    		puissanceAttaque = (item[503] * 12000) * (1.05 * weapons_tech);
    		
    		/* PHP Code */
    		/*
    		while ($PuissanceAttaque > 20) {
    			$RandomDefense = rand(401, 410);
    	
    			$SelectionDefense = $DefenseAdversaire[$RandomDefense];
    			if ($SelectionDefense > 0) {
    				if ($PuissanceAttaque > ($SelectionDefense * $TableauDeDefense[$RandomDefense])) {
    					$PuissanceAttaque = $PuissanceAttaque - ($SelectionDefense * $TableauDeDefense[$RandomDefense]);
    					$DefenseAdversaire[$RandomDefense] = $DefenseAdversaire[$RandomDefense] - 1;
    				}
    			}
    		}
    		*/
    		while (puissanceAttaque > 20) {
    			randomDefense = (rand()%10)+400;
    	
    			selectionDefense = item[randomDefense];
    			if (selectionDefense > 0) {
    				if (puissanceAttaque > (selectionDefense * item[randomDefense][s])) {
    					puissanceAttaque = puissanceAttaque - (selectionDefense * item[randomDefense][s]);
    					item[randomDefense] = item[randomDefense] - 1;
    				}
    			}
    		}
    
    		/* Now a loop for repeating back the defence scores */
    		printf("\nCalculating Attack, in huge attacks this might take a while.\n\n");
    		printf("After the attack the defender has.\n");
    		for ( id = 401; id < 411; id++ ) {
    			printf("%s: %i\n",name[id],item[id]);
    		}
    	}
    }
    /*Script by Anthony (MadnessRed) (c) 2008 - http://madnessred.co.cc */
    It is an IPM sim for the browser game XNova. However when I compile it I am getting a load of errors. I am used to php telling me the exact error and the line however the error I am getting don't make sense to me. Prehaps someone could help explain.

    Copy and paste from terminal is..

    madnessred@anthony-desktop:~/Programs/Basic$ gcc -o ipmsim -lm ipmsim.c
    ipmsim.c: In function ‘main’:
    ipmsim.c:47: error: conflicting types for ‘item’
    ipmsim.c:47: error: previous declaration of ‘item’ was here
    ipmsim.c:48: error: conflicting types for ‘item’
    ipmsim.c:47: error: previous declaration of ‘item’ was here
    ipmsim.c:48: error: conflicting types for ‘item’
    ipmsim.c:48: error: previous declaration of ‘item’ was here
    ipmsim.c:48: error: conflicting types for ‘item’
    ipmsim.c:48: error: previous declaration of ‘item’ was here
    ipmsim.c:48: error: conflicting types for ‘item’
    ipmsim.c:48: error: previous declaration of ‘item’ was here
    ipmsim.c:48: error: conflicting types for ‘item’
    ipmsim.c:48: error: previous declaration of ‘item’ was here
    ipmsim.c:48: error: conflicting types for ‘item’
    ipmsim.c:48: error: previous declaration of ‘item’ was here
    ipmsim.c:48: error: conflicting types for ‘item’
    ipmsim.c:48: error: previous declaration of ‘item’ was here
    ipmsim.c:48: error: conflicting types for ‘item’
    ipmsim.c:48: error: previous declaration of ‘item’ was here
    ipmsim.c:48: error: conflicting types for ‘item’
    ipmsim.c:48: error: previous declaration of ‘item’ was here
    ipmsim.c:48: error: conflicting types for ‘item’
    ipmsim.c:48: error: previous declaration of ‘item’ was here
    ipmsim.c:49: error: ‘s’ undeclared (first use in this function)
    ipmsim.c:49: error: (Each undeclared identifier is reported only once
    ipmsim.c:49: error: for each function it appears in.)
    ipmsim.c:52: error: conflicting types for ‘name’
    ipmsim.c:52: error: previous declaration of ‘name’ was here
    ipmsim.c:52: error: conflicting types for ‘name’
    ipmsim.c:52: error: previous declaration of ‘name’ was here
    ipmsim.c:52: error: conflicting types for ‘name’
    ipmsim.c:52: error: previous declaration of ‘name’ was here
    ipmsim.c:52: error: conflicting types for ‘name’
    ipmsim.c:52: error: previous declaration of ‘name’ was here
    ipmsim.c:52: error: conflicting types for ‘name’
    ipmsim.c:52: error: previous declaration of ‘name’ was here
    ipmsim.c:52: error: conflicting types for ‘name’
    ipmsim.c:52: error: previous declaration of ‘name’ was here
    ipmsim.c:52: error: conflicting types for ‘name’
    ipmsim.c:52: error: previous declaration of ‘name’ was here
    ipmsim.c:52: error: conflicting types for ‘name’
    ipmsim.c:52: error: previous declaration of ‘name’ was here
    ipmsim.c:52: error: conflicting types for ‘name’
    ipmsim.c:52: error: previous declaration of ‘name’ was here
    ipmsim.c:55: warning: assignment makes integer from pointer without a cast
    ipmsim.c:56: warning: assignment makes integer from pointer without a cast
    ipmsim.c:57: warning: assignment makes integer from pointer without a cast
    ipmsim.c:58: warning: assignment makes integer from pointer without a cast
    ipmsim.c:59: warning: assignment makes integer from pointer without a cast
    ipmsim.c:60: warning: assignment makes integer from pointer without a cast
    ipmsim.c:61: warning: assignment makes integer from pointer without a cast
    ipmsim.c:62: warning: assignment makes integer from pointer without a cast
    ipmsim.c:63: warning: assignment makes integer from pointer without a cast
    ipmsim.c:64: warning: assignment makes integer from pointer without a cast
    ipmsim.c:107: error: expected ‘)’ before ‘name’
    ipmsim.c:112: error: ‘puissanceAttaque’ undeclared (first use in this function)
    for example there is an error
    warning: assignment makes integer from pointer without a cast
    however I don't know what an assignment, pointer or a cast is.

    any help would be great.

    thanks

    MadnessRed

    ps I have read posts with the poster being crucified for posting because everyone says that he is cheating on there college homework. I don't expect this as I am not asking for some1 to do it for me, just to help explain the errors to me and what I am doing wrong.
    Last edited by Salem; 08-22-2008 at 06:38 PM. Reason: No php

  2. #2
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144
    You must be new to C programming --- you are declaring multiple 'item[]'
    Code:
        int item[502],item[503],missiles; 
        int item[401],item[402],item[403],item[404],item[405],item[406],item[407],item[408],item[409],item[410]; 
        int item[401][s],item[402][s],item[403][s],item[404][s],item[405][s],item[406][s],item[407][s],item[408][s],item[409][s],item[410][s];
    ffor example, item[401] is declaring item to be an array of ints of size 401. Then you declare item[402] to be an array of ints of size 402. So you have multiple declarations for the same variable name --- CAN'T DO THAT.

    Declare int item[] one time to be the size you need it to be. If you want to 'initialize' a certain item[], you do it like

    item[400] = 100;

    You really need to understand how to declare variables, especially arrays. Hit the books!

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Unfortunately, everything. You need to start at the beginning and read some tutorials. You can start here.

  4. #4
    Registered User
    Join Date
    Aug 2008
    Posts
    10
    :'(

    Yes, I am new to C, so can you recommend a good tutorial on c arrays?

  5. #5

  6. #6
    * noops's Avatar
    Join Date
    Jun 2008
    Posts
    108
    I would also look into structures as that seems suited to what you are doing. It would let you do something like:

    TestItem.Name
    TestItem.ShieldCap

    To reference values.

  7. #7
    Registered User
    Join Date
    Jun 2008
    Posts
    266
    I would actually recommend reading a good book. Programming in C is probably my favorite.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program giving errors
    By andy bee in forum C Programming
    Replies: 5
    Last Post: 08-11-2010, 10:38 PM
  2. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  3. I'm a newbie and I can't understand the errors in my program
    By iluvmyafboys in forum C++ Programming
    Replies: 19
    Last Post: 02-20-2002, 10:40 AM
  4. Simple Program wont execute after compiles w. no errors
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 02-03-2002, 04:24 PM
  5. Pls explain how this program works...
    By Unregistered in forum C Programming
    Replies: 9
    Last Post: 01-05-2002, 09:53 AM