Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

ISO C++ forbids decleration of `add` with no type

hello world fflush

  • Please log in to reply
4 replies to this topic

#1 Phoenixz


    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 222 posts

Posted 25 December 2008 - 04:10 PM

Hai, I think this maybe a compiler error? i was trying to create a function named add, see code below:

 * How to make functions
 * functions are blocks of code, given a unique name..
 * Greet()
 * {
 * printf("Hello World\n");
 * }
 * and to use in a code just simply "greet();"
 * must be at the top, and not in any other function
//start function add

#include <stdio.h>

     int num1, num2;
     int total;
     printf("Please enter the first number: ");
     scanf("%d", &num1);
     printf("%d", &num2);
     total = num1 + num2;
     printf("The total of the two numbers is %d\n", total);
//end function add

and it says what is wrote on the topic. Is it a compiler error like I first thought? and how would I get around it?
  • 0

#2 TkTech


    The Crazy One

  • Retired Mod
  • PipPipPipPipPipPipPip
  • 1144 posts
  • Location:Ottawa, Ontario

Posted 25 December 2008 - 06:56 PM


#include <stdio.h>

void add(void);

void add(void)

  • 0
Helpful CODECALL Links: Join Us, Guidelines, FAQ, Post a Tutorial

#3 Feral


    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 158 posts

Posted 25 December 2008 - 07:14 PM

When you declare a function it has to have a type, if you are returning no information then as TkTech said make the type 'void' other wise make the type the same as what you want to return (int, float, double, ect).
  • 0

#4 Phoenixz


    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 222 posts

Posted 26 December 2008 - 02:31 AM

Doh, these tutorials suck, first they didn't tell me of the #include <strings.h> and now it didn't tell me of this..

Thanks very much for your help guys!
  • 0

#5 WingedPanther73


    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 26 December 2008 - 06:47 AM

They really suck. It should be #include <string>
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download