Like Tree2Likes

Need help. Can't identify error.

This is a discussion on Need help. Can't identify error. within the C Programming forums, part of the General Programming Boards category; Beginner here. This is the first program I made. There seems to be an error. Please help me fix it. ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    25

    Lightbulb Need help. Can't identify error.

    Beginner here. This is the first program I made. There seems to be an error. Please help me fix it. Thanks.

    Code:
    #include <stdio.h>
    
    int main()
    {
    	int a, b, c, ans1, ans2, ans3, ans4, ans5;
    	printf("Think of three Real numbers... \n\n\n");
    	printf("Enter your first number\n");
    	scanf("%d", &a);
    	printf("Enter your second number\n");
    	scanf("%d", &b);
    	printf("Enter your third number\n");
    	scanf("%d", &c);	
    	ans1 = a*-(b+c);
    	ans2 = (b*b)-4(a*c);
    	ans3 = (a*a)+(b*b*b)+(c*c)-12;
    	ans4 = ((a+b)/(c-b))-(3(b*b))+((4(b))/(3(c)));
    	ans5 = 3(a*a)-2(b*b)-9.14;
    	printf("\nFor equation 1, we have the answer %d,\nFor equation 2, we have %d,\nFor equation 3, we have %d,\nFor equation 4, we have %d and,\nFor equation 5, we have %d, ", ans1, ans2, ans3, ans4, ans5);
    	
    	return 0;
    }
    Last edited by bummielove; 07-04-2011 at 08:58 AM.

  2. #2
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    First of all you don’t have to print your message in just big front. We all here i believe can read with the normal font! And there is no necessity to print that with an annoying bold!

    **With the normal font** Now tell us what excatly u'r having issues with? Rather than just saying there is a problem.

    ssharish
    Last edited by ssharish2005; 07-04-2011 at 08:51 AM.
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    2,575
    "3(y)" is not right you need to do "3*(y)" instead.

    Tim S.

  4. #4
    Registered User
    Join Date
    Jul 2011
    Posts
    25
    When I'm trying to run the program, it keeps on displaying " error: called object 4 is not a function" There.

  5. #5
    Registered User
    Join Date
    Jul 2011
    Posts
    25
    Quote Originally Posted by stahta01 View Post
    "3(y)" is not right you need to do "3*(y)" instead.

    Tim S.
    Thanks!

  6. #6
    Registered User
    Join Date
    Jul 2011
    Posts
    25
    Quote Originally Posted by ssharish2005 View Post
    First of all you don’t have to print your message in just big front. We all here i believe can read with the normal font! And there is no necessity to print that with an annoying bold!

    **With the normal font** Now tell us what excatly u'r having issues with? Rather than just saying there is a problem.

    ssharish
    When I'm trying to run the program, it keeps on displaying " error: called object 4 is not a function" There.

  7. #7
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Take a look at your equations:
    Code:
    ans1 = a*-(b+c);
    ans2 = (b*b)-4(a*c);
    ans3 = (a*a)+(b*b*b)+(c*c)-12;
    ans4 = ((a+b)/(c-b))-(3(b*b))+((4(b))/(3(c)));
    ans5 = 3(a*a)-2(b*b)-9.14;
    Then take a look at what you were told:
    "3(y)" is not right you need to do "3*(y)" instead.
    Tim S.
    No apply this idea to all of your equations. C is not a calculator parser, it needs to be told exactly what you want it to do.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  8. #8
    Registered User
    Join Date
    Jul 2011
    Posts
    25
    Quote Originally Posted by stahta01 View Post
    "3(y)" is not right you need to do "3*(y)" instead.

    Tim S.
    That's what I needed! Thank you Tim S! \m/ Thanks! Thanks to those who helped me here!

  9. #9
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Minor issues about readable code...

    1) The most accepted form of main is.. int main (void) ... empty brackets signify "any parameters" where specifying void signals "no parameters".

    2) You would do well to split your final printf() into multiple statements, perhaps one per calculation. The final result is the same but the code will be far easier to read.

    3) Choosing more descriptive but not overly verbose variable names also helps readability of code. For example instead of a, b, c you could use FirstInput, SecondInput and ThirdInput ... again to make it easier to read and follow your code.

    Other than the syntax errors pointed out by the others, I'd say you're off to a pretty good start.

    One final tip... Turn the warning levels in your compiler all the way up and treat all reports as errors to be corrected. You'll be surprised how smart your compiler is about helping you write good code...
    Last edited by CommonTater; 07-04-2011 at 09:08 AM.

  10. #10
    Registered User
    Join Date
    Jul 2011
    Posts
    25
    Quote Originally Posted by AndrewHunter View Post
    Take a look at your equations:
    Code:
    ans1 = a*-(b+c);
    ans2 = (b*b)-4(a*c);
    ans3 = (a*a)+(b*b*b)+(c*c)-12;
    ans4 = ((a+b)/(c-b))-(3(b*b))+((4(b))/(3(c)));
    ans5 = 3(a*a)-2(b*b)-9.14;
    Then take a look at what you were told:


    No apply this idea to all of your equations. C is not a calculator parser, it needs to be told exactly what you want it to do.
    Thank You Sir!

  11. #11
    Registered User
    Join Date
    Jul 2011
    Posts
    25
    Quote Originally Posted by CommonTater View Post
    Minor issues about readble code...

    1) The most accepted form of main is.. int main (void) ... empty brackets signify "any parameters" where specifying void signals "no parameters".

    2) You would do well to split your final printf() into multiple statements, perhaps one per calculation. The final result is the same but the code will be far easier to read.


    3) Choosing more descriptive but not overly verbose variable names also helps readability of code. For example instead of a, b, c you could use FirstInput, SecondInput and ThirdInput ... again to make it easier to read and follow your code.

    Other than the syntax errors pointed out by the others, I'd say you're off to a pretty good start.

    One final tip... Turn the warning levels in your compiler all the way up and treat all reports as errors to be corrected. You'll be surprised how smart our compiler is about helping you write good code...
    Thank you for the tip! THAAAAAAAAANKS!

  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,725
    Quote Originally Posted by CommonTater
    1) The most accepted form of main is.. int main (void) ... empty brackets signify "any parameters" where specifying void signals "no parameters".
    Actually, the empty parentheses mean "no parameters" because this is a function definition. However, for many other functions, you will probably have a corresponding prototype, in which case the empty parentheses will indeed mean "any parameters", so you might as well be consistent.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #13
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by laserlight View Post
    Actually, the empty parentheses mean "no parameters" because this is a function definition. However, for many other functions, you will probably have a corresponding prototype, in which case the empty parentheses will indeed mean "any parameters", so you might as well be consistent.
    In case you were curious Tater, per the standard section 6.7.5.3:
    14 An identifier list declares only the identifiers of the parameters of the function. An empty
    list in a function declarator that is part of a definition of that function specifies that the
    function has no parameters.
    The empty list in a function declarator that is not part of a
    definition of that function specifies that no information about the number or types of the
    parameters is supplied.124)
    I know I always try to look up these things up.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  14. #14
    Registered User
    Join Date
    May 2009
    Posts
    2,575
    @AndrewHunter: When was that (standard section 6.7.5.3) change to standard approved?

    Tim S.

  15. #15
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,725
    Quote Originally Posted by stahta01
    When was that (standard section 6.7.5.3) change to standard approved?
    In 1999, but it is not really a change since the wording was retained from 1989.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. identify my algorithm, please!
    By MK27 in forum Tech Board
    Replies: 8
    Last Post: 11-25-2009, 06:01 AM
  2. How to identify arrow-chars?
    By Zarniwoop in forum C Programming
    Replies: 5
    Last Post: 05-31-2009, 01:07 PM
  3. can you identify this car?
    By axon in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 07-19-2004, 02:59 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21