Thread: I am so lost...Please help

  1. #1
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179

    I am so lost...Please help

    Ok I am trying to get this extremely simple code to work(it is in the book I am trying to use to learn C from) any ways my compiler says I have 12 errors!!
    I know that is pathetic for something this small but it is my first program and I looked it over and I just can't find out what is wrong with it. Anyways here is the source code:

    /* Program multiplies two numbers together and displays the results*/

    #include <stdio.h>

    int a,b,c;
    int product(int x, int y);

    main()
    {
    /* Input the first number */

    printf("Enter a number between 1 and 100: ")
    scan(%d", &b);
    c=product(a,b);
    printf ("%d times %d=%d\n", a,b,c);

    /* Input the second number*/

    printf("Enter another number between 1 and 100: ");
    scanf("%d, &b);

    /* Calculate and display the product */

    c=product(a, b);
    printf ("%d times %d = %d\n", a,b,


    return 0;
    }

    /*Function returns the product of its two arguments */

    int product(int x, int y)
    {
    return (x*y);
    }


    Keep in mind it isn't the book, I am trying not to just copy and paste(it is an e-book) because I want to get a feel for the language so that is where the mistakes come from. Please help.
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    41
    I found a couple simple misakes,



    /* Input the first number */

    printf("Enter a number between 1 and 100: ")
    scan(%d", &b);


    printf(" enter a number between 1 and 100: ");
    forgot the semicolen at the end

    scanf("%d", &b);
    forgot the f in scanf and " in "%d",

    ======================================

    /* Calculate and display the product */

    it's:
    printf("%d times %d = %d\n", a,b,);
    forgot the ) and the semicolen at the end.

    That's all I could find.
    Shouldent NULL be, 78, 85, 76, 76, or just 0 or, 4E, 55, 4C, 4C

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    7
    here you go dude - I took out the function

    Code:
    #include <stdio.h> 
    
    int a,b,c; 
    int product(int x, int y); 
    
    int main() 
    { 
    /* Input the first number */ 
    
    printf("Enter a number between 1 and 100: "); 
    scanf("%d", &b); 
     
    
    /* Input the second number*/ 
    
    printf("Enter another number between 1 and 100: "); 
    scanf("%d", &a); 
    
    /* Calculate and display the product */ 
    
    c = (a * b); 
    printf("%d times %d = %d\n", a,b,c); 
    
    getch();
    
    return 0; 
    }

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    41
    I dident think the function had to be in there but i'm still not that good of a C guy but i'm getting there.
    Shouldent NULL be, 78, 85, 76, 76, or just 0 or, 4E, 55, 4C, 4C

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    7
    Heres how you would do it if you wanted the function.

    Code:
    #include <stdio.h> 
    
    int a,b,c; 
    int product(int x, int y); 
    
    int multiply(int num1, int num2) 
    {
    
    int total = 0; /* defining what to send back to main */
    
    total = num1 * num2;
    
    return(total);
    }
    
    int main() 
    { 
    /* Input the first number */ 
    
    printf("Enter a number between 1 and 100: "); 
    scanf("%d", &b); 
     
    
    /* Input the second number*/ 
    
    printf("Enter another number between 1 and 100: "); 
    scanf("%d", &a); 
    
    /* Calculate and display the product */ 
    
     
    printf("%d times %d = %d\n", b,a,multiply(a,b)); 
    
    getch();
    
    return 0; 
    }

  6. #6
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179
    Thanks I will try out those and see, the books code is right(I tried copying and pasting just to see)but I want to try and type out the code so I can learn it...still I don't know what I mistyped, oh well thanks a lot.

    __________________________________________________ __------------------------------------------------------------------------------------
    Damn This Site is helpful
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The getting lost and walking in circles
    By Mario F. in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 05-07-2008, 09:53 AM
  2. I lost my laptop, DVD and money
    By Sang-drax in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 10-01-2004, 07:13 PM
  3. lost disk
    By Benzakhar in forum Linux Programming
    Replies: 7
    Last Post: 01-11-2004, 06:18 PM
  4. Lost ID number
    By ripper079 in forum C++ Programming
    Replies: 13
    Last Post: 10-04-2002, 12:51 PM
  5. API, LOST... help
    By Unregistered in forum Windows Programming
    Replies: 5
    Last Post: 03-13-2002, 03:19 PM