*NOOB* attempt to make a calc prog

This is a discussion on *NOOB* attempt to make a calc prog within the C Programming forums, part of the General Programming Boards category; im not even half way through my book yet but i figured wat the hell ill give making a calc ...

  1. #1
    Registered User Inferno's Avatar
    Join Date
    Nov 2003
    Posts
    24

    *NOOB* attempt to make a calc prog

    im not even half way through my book yet but i figured wat the hell ill give making a calc a try while i was on vaction. Also i would like to say i did this in a notebook didnt have a pc or nething to compile it on *sigh* neway here the code

    Code:
    #include <stdio.h>
    
    int x
    int y
    int add_num(int x, int y)
    int sub_num(int x, int y)
    int mutli_num(int x, int y)
    int divid_num(int x, int y)
    
        int add_num = +=;
        int sub_num = -=;
        int multi_num = *=;
        int divid_num = /=;
    {
        int result;
        result = x"+=,-=,*=,/="y;
        return result;
    }
    int main()
    {
    char name[200]
    int sum;
    
    sum =  add_num,sub_num,multi_num,divid_num(x,y);
    printf("input:">>name>>\n");
    printf("result: %d \n",sum);
    
      system("PAUSE");	
      return 0;
    }
    i think it was a decent attempt for a noob such as my self...but neway could someone lend me a hand here??????

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    So many errors so little time
    Code:
    int x
    int y
    Avoid the use of global variables when you can simply pass them

    Code:
    int add_num(int x, int y)
    int sub_num(int x, int y)
    int mutli_num(int x, int y)
    int divid_num(int x, int y)
    Forgot the semi colons at the end of the lines

    Code:
        int add_num = +=;
        int sub_num = -=;
        int multi_num = *=;
        int divid_num = /=;
    Ain't gonna work

    Code:
    {
        int result;
        result = x"+=,-=,*=,/="y;
        return result;
    }
    Where is the function header? The result = line is totally invalid

    Code:
    sum =  add_num,sub_num,multi_num,divid_num(x,y);
    Won't do what you think it'll do

    Code:
    printf("input:">>name>>\n");
    Won't do what you think it'll do.

  3. #3
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Code:
    C:\Documents and Settings\moi>gcc dumb.c -std=c99 -Wall -pedantic
    dumb.c:4: syntax error before "int"
    dumb.c:5: syntax error before "int"
    dumb.c: In function `add_num':
    dumb.c:7: parse error before "int"
    dumb.c:11: parameter `sub_num' is initialized
    dumb.c:11: conflicting types for `sub_num'
    dumb.c:7: previous declaration of `sub_num'
    dumb.c:11: parse error before '-=' token
    dumb.c:6: parm types given both in parmlist and separately
    dumb.c:16: parse error before string constant
    dumb.c: In function `main':
    dumb.c:22: warning: ISO C forbids nested functions
    dumb.c:22: syntax error before "int"
    dumb.c:24: `sum' undeclared (first use in this function)
    dumb.c:24: (Each undeclared identifier is reported only once
    dumb.c:24: for each function it appears in.)
    dumb.c:24: `sub_num' undeclared (first use in this function)
    dumb.c:24: `multi_num' undeclared (first use in this function)
    dumb.c:24: warning: implicit declaration of function `divid_num'
    dumb.c:24: `x' undeclared (first use in this function)
    dumb.c:24: `y' undeclared (first use in this function)
    dumb.c:24: warning: left-hand operand of comma expression has no effect
    dumb.c:24: warning: left-hand operand of comma expression has no effect
    dumb.c:24: warning: left-hand operand of comma expression has no effect
    dumb.c:25: `name' undeclared (first use in this function)
    dumb.c:25: stray '\' in program
    dumb.c:25:26: warning: multi-line string literals are deprecated
    dumb.c:25: `n' undeclared (first use in this function)
    dumb.c:25: parse error before string constant
    dumb.c:25: stray '\' in program
    dumb.c:26:22: warning: multi-line string literals are deprecated
    dumb.c:28:16: warning: multi-line string literals are deprecated
    dumb.c:28:16: missing terminating " character
    dumb.c:25:26: possible start of unterminated string literal
    
    C:\Documents and Settings\moi>
    hello, internet!

  4. #4
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Code:
    #include <stdio.h>
     
    int x
    int y
    int add_num(int x, int y)
    int sub_num(int x, int y)
    int mutli_num(int x, int y)
    int divid_num(int x, int y)
     
    int add_num = +=;
    int sub_num = -=;
    int multi_num = *=;
    int divid_num = /=;
    {
    int result;
    result = x"+=,-=,*=,/="y;
    return result;
    }
    As far as I can tell you are trying to make a set of functions. The way you have it laid out won't work. You have to match the routines the function is made of with the declarations. That should be:

    Code:
    int x;
    int y;
    // Placed code to right for smaller size
    int add_num(int x, int y) {int add_num = +=;}
    int sub_num(int x, int y) {int sub_num = -=;}
    int mutli_num(int x, int y) {int multi_num = *=;}
    int divid_num(int x, int y) {int divid_num = /=;}
    The section with the result is not used so I didn't make changes to that.

    The next error I see is this:

    Code:
    sum = add_num,sub_num,multi_num,divid_num(x,y);
    That isn't going to do what you expect. Since I'm assuming you want the sum from adding all of those, here's what you might want to try:

    Code:
    sum = add_num(x,y) + sub_num(x,y) + multi_num(x,y) + divid_num(x,y);
    To output a string, change:

    Code:
    printf("input:">>name>>\n");
    to:

    Code:
    printf("input: %s \n", name);
    Oh and add a semicolon to this:

    Code:
    char name[200]
    Hope I got everything but I may have missed something.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to make a Packet sniffer/filter?
    By shown in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2009, 08:51 PM
  2. trying to make a KenGen ( for a game tool )
    By lonewolfy in forum C# Programming
    Replies: 4
    Last Post: 03-28-2007, 08:23 AM
  3. how to make a windows application
    By crvenkapa in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 09:59 AM
  4. Win32 Common Controls in C++, how do i make and use them?
    By C+noob in forum Windows Programming
    Replies: 6
    Last Post: 01-09-2006, 10:53 AM
  5. want to make this small program...
    By psycho88 in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2005, 01:05 AM

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