By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,234 Members | 1,889 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,234 IT Pros & Developers. It's quick & easy.

need help

P: 1
hey, im trying to program a game that lets you buy weapons and sell them on and stuff. obviously more complicated than that but you get my drift. im getting a few errors i cant fix.

function 'glock17' should have a prototype (32)
type mismatch in redeclaration of 'glock17' (106)
misplaced else (149)
misplaced else (159)
function 'weaponm' should have a prototype (190)

cant find anything on prototypes that i can understand

heres the source:

Expand|Select|Wrap|Line Numbers
  1. #include<conio.h>
  2. #include<stdio.h>
  3. int glock;
  4. int glockinv;
  5. int suitcase,cash,buysell;
  6.  
  7.  
  8.  
  9.  
  10.                             void glock17()
  11.                             {
  12.                             char howmuch;
  13.                             int glocktemp,glockinv;
  14.  
  15.  
  16.                             printf("would you like to buy(1) or sell(2) some glock17's?\n\n");
  17.                             scanf("%c",&buysell);
  18.                             if(buysell=1)
  19.                             printf("\nHow many would ya like?");
  20.                             {
  21.                             scanf("%i",&glocktemp);
  22.                               if(glocktemp>200)
  23.                              {
  24.                               printf("\nYou cant buy that much\n");
  25.                               getchar();
  26.                               glock17();
  27.                              }
  28.  
  29.                               else if(glocktemp=0)
  30.                               {
  31.                               void weaponsmark();
  32.                               getchar();
  33.                               glock17();
  34.                               }
  35.  
  36.                               else if(cash<(glocktemp*50)
  37.                               {
  38.                               printf("\nYou Don't have enough money");
  39.                               getchar();
  40.                               glock17();
  41.                               }
  42.                               else
  43.                               {
  44.                               glockinv=weapontemp;
  45.                               suitcase=suitcase-glockinv;
  46.                               cash=cash-(glocktemp*50)
  47.                               printf("\nYou have just bought %i Glocks for %i",glockinv,glocktemp);
  48.                               printf("\nYou have %i glock and %i space left",glockinv, suitcase);
  49.                               getchar();
  50.                               clrscr();
  51.                               weaponsmark();
  52.                              }
  53.                              }
  54.                             else
  55.                             {
  56.                             if (glockinv>1)
  57.  
  58.                             printf("\nHow many would you like to sell?");
  59.                             scanf("%i,"&drugtemp);
  60.                             cash=cash+(glockinv*50)
  61.                             printf("\nYou sold %i's worth of Glocks");
  62.                             glockinv=glockinv-drugtemp;
  63.                             }
  64.                             else
  65.                             Printf("\nyou don't have any Glocks!")
  66.                             weaponsmark();
  67.                             }
  68.                           }
  69.  
  70.  
  71.            void suitcasefunc()
  72.            {
  73.            suitcase=200;
  74.            }
  75.            void cashfunc()
  76.            {
  77.             cash=50000
  78.            }
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86. void weaponsmark()
  87.  
  88. char weaponm;
  89.  
  90. do
  91. {
  92.  
  93.      printf("\n\t\t a.Buy Glock 17 (Handgun)");
  94.      printf("\n\t\t b.Buy M9 (Shotgun)");
  95.      printf("\n\t\t c.Buy MP7 (Sub Machine Gun)");
  96.      printf("\n\t\t d.Buy M4 (Rifle)");
  97.      printf("\n\t\t e.Buy SV210 (Sniper Rifle)");
  98.      printf("\n\t\t f.Buy Barret 50 .cal (Armor Piercing Rifle)");
  99.      printf("\n\t\t g.Buy M203 (Grenade Launcher)");
  100.      printf("\n\t\t h.Buy LAW 24 (Rocket Launcher)");
  101.      printf("\n\t\t i.Buy Torque Bow (sticky bombs)");
  102.      printf("\n\t\t j.Buy Nuke");
  103.      printf("\n\t\t k.Buy Hammer Of Dawn (ION Cannon)");
  104.      printf("\n\nWeapon Dealer: What kind of boom stick would you like
  105. today, sir?");
  106.      weaponm=getchar();
  107.  
  108.      switch(weaponm)
  109.      {
  110.  
  111.      case 'a':glock17();
  112.           break;
  113.    /*  case 'b':m9();
  114.           break;
  115.      case 'c':mp7();
  116.           break;
  117.      case 'd':m4();
  118.           break;
  119.      case 'e':sv210();
  120.           break;
  121.      case 'f':barret();
  122.           break;
  123.      case 'g':m203();
  124.           break;
  125.      case 'h':law24();
  126.           break;
  127.      case 'i':torque();
  128.           break;
  129.      case 'j':nuke();
  130.           break;
  131.      case 'k':ION();
  132.           break; */
  133.      case 'l':break;
  134.  
  135.      default: printf("\n Invalid Menu Choice");
  136.      getchar();
  137.      }
  138. }
  139. while(weaponm!='l');
  140. printf("\nGoodbye");
  141. getchar();
  142. }
  143.  
  144.  
  145. /*void startmenu()
  146. {
  147. char choice;
  148.  
  149. do
  150. {
  151.     clrscr();
  152.     printf("\n\t\t d.Drugs Market");
  153.     printf("\n\t\t w.Weapons Market");
  154.     printf("\n\t\t b.Buy Upgrade");
  155.     printf("\n\t\t v.View Stats");
  156.     printf("\n\t\t f.Fly");
  157.     printf("\nEnter Choice");
  158.     choice=getchar();
  159.  
  160.     switch(choice)
  161.     {
  162.  
  163.     case 'a':printf("\n\nnumber1");
  164.         getchar();
  165.          break;
  166.  
  167.     case 'b':printf("\n\nnumber2");
  168.          getchar();
  169.          break;
  170.  
  171.     case 'c':break;
  172.  
  173.     default: printf("\n Invalid Menu Choice");
  174.     getchar();
  175.     }
  176. }
  177. while(choice!='c');
  178. printf("\nGoodbye");
  179. getchar();
  180. }
  181.  
  182.  */
  183. void main()
  184. {
  185. cashfunc();
  186. suitcasefunc();
  187. weaponsmark();
  188. weaponm();
  189. }
  190.  
  191.  
  192.  
thanks in advance
Mar 20 '07 #1
Share this Question
Share on Google+
1 Reply


sicarie
Expert Mod 2.5K+
P: 4,677
So that's just saying that you need to declare those functions you create. For instance, if I want to create a function that changes celsius to farenheit, it would look something like:
Expand|Select|Wrap|Line Numbers
  1. float celsiusToFarenheit(float faren) {
  2.     float cel = (5/9) * (faren-32);
  3.     return cel;
  4. }
  5.  
However, the compiler needs the prototype to be able to read it, so you would also need to include:
Expand|Select|Wrap|Line Numbers
  1. float celsiusToFarenheit(float faren);
  2.  
Best practice dictates putting this by your headers (though I've never played around with the declarations - I'm not sure it's entirely necessary).

So, for C++:
Expand|Select|Wrap|Line Numbers
  1. include <iostream>
  2. using namespace std;
  3. float celsiusToFarenheit(float faren);
  4. int main()
  5. {
  6.     float temp;
  7.     cout << "Enter a temp: ";
  8.     cin >> temp;
  9.     cout << "The Celsius equivalent is: " << celsiusToFarenheit(temp) << endl;
  10.     return 0;
  11. }
  12.  
  13. float celsiusToFarenheit(float faren) {
  14.     float cel = (5/9) * (faren-32);
  15.     return cel;
  16. }
  17.  
Mar 20 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.