ok, yes, I need help with my homework!

This is a discussion on ok, yes, I need help with my homework! within the C Programming forums, part of the General Programming Boards category; ok, here's the question: Write a program that reads three integers and then prints them in the order read and ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    18

    ok, yes, I need help with my homework!

    ok, here's the question: Write a program that reads three integers and then prints them in the order read and reversed. Use three functions, one to read the data, one to print them in the order read, and one to print them reversed.
    Now I know that this should be a simple problem, but hey...i'm new.
    Here's what I have so far:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    /*Prototype Declarations*/
      void  printforward (int *a,
                          int *b, 
                          int *c);
      void  printback (int *a, 
                       int *b, 
                       int *c);
      void   readit (int a, int b, int c);
    
    
    
    int main(void)
    {
      /*Local Definitions*/
      int a;
      int b;
      int c;
      
      
      /*Statements*/
      readit       (a, b, c);
      printforward (&a, &b, &c);
      printback    (&c, &b, &a);
      
      return 0;
    }  /*main*/
      
      /*====================readit===================*/
      
      void readit (int a,
                   int b,
                   int c);
    {
      /*Statements*/
      printf("\nEnter three integers:\n");
      scanf("%d %d %d", &a, &b, &c);
    } /*readit*/  
     
       /*================printforward================*/
       void printforward (int *a,
                          int *b,
                          int *c)
    
    { 
         /*Statements*/     
            printf("\nThe numbers forward are: %d %d %d", *a, *b, *c);
            return;
    }/*printforward*/
       /*================printback===================*/
      void printback (int *a,
                      int *b,
                      int *c)
      {   
          /*Statements*/  
             printf("\nThe numbers backward are: %d %d %d", *c, *b, *a);
              return; 
     /*printback*/          
    system("PAUSE");	
    }
    Now admittedly, I'm a bit clueless right now, but I would appreciate any help you guys could give.
    Thanks
    melee
    Last edited by melee; 09-22-2004 at 02:07 AM. Reason: using code tags

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    You need to pass the variables to readit() by reference instead of by value. In other words, pass the variables like you did to printforward() and printback().

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by melee
    Now admittedly, I'm a bit clueless right now, but I would appreciate any help you guys could give.
    Thanks
    melee
    Well, you could start by actually reading the board Announcements. In doing so, you'll learn how to use [code] tags. After you figure that out, click the little edit button and edit your post using said code tags.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    18
    quzah--done and done
    bithub -- thanks for the advice this is the updated code

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    /*Prototype Declarations*/
      void  printforward (int *a,
                          int *b, 
                          int *c);
      void  printback (int *a, 
                       int *b, 
                       int *c);
      void   readit (int *a, int *b, int *c);
    
    
    
    int main(void)
    {
      /*Local Definitions*/
      int a;
      int b;
      int c;
      
      
      /*Statements*/
      readit       (&a, &b, &c);
      printforward (&a, &b, &c);
      printback    (&c, &b, &a);
      
      return 0;
    }  /*main*/
      
      /*====================readit===================*/
      
      void readit (int &a,
                   int &b,
                   int &c);
    {
      /*Statements*/
      printf("\nEnter three integers:\n");
      scanf("%d %d %d", &a, &b, &c);
    } /*readit*/  
     
       /*================printforward================*/
       void printforward (int *a,
                          int *b,
                          int *c)
    
    { 
         /*Statements*/     
            printf("\nThe numbers forward are: %d %d %d", *a, *b, *c);
            return;
    }/*printforward*/
       /*================printback===================*/
      void printback (int *a,
                      int *b,
                      int *c)
      {   
          /*Statements*/  
               printf("\nThe numbers backward are: %d %d %d", *c, *b, *a);
              return; 
     /*printback*/          
    system("PAUSE");	
    }
    I'm still getting some errors...It keeps telling me I have parse errors. However, those parse errors go away when I remove the preceeding open bracket "{" Any idea why this might be? It looks to me like the brackets are correct as is...
    melee

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
      void readit (int &a,
                   int &b,
                   int &c);
    {
      /*Statements*/
      printf("\nEnter three integers:\n");
      scanf("%d %d %d", &a, &b, &c);
    } /*readit*/
    1) This is wrong. If you want pointers, those should be *. If you want actual pass-by-value non-pointer variables, just remove those. However, I assume you really want pointers. If this is the case, then you won't need the & for your scanf calls, since scanf deals directly with pointers anyway.

    2) This semicolon here shouldn't be here. Since it is, it's trying to be another prototype, instead of the actual function definition.

    And thanks for editing your post.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Sep 2004
    Posts
    18
    Got it...thanks for your help!! (I'm sure I'll be back)
    melee

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Homework
    By kermi3 in forum C Programming
    Replies: 10
    Last Post: 09-27-2001, 05:49 PM
  2. Homework
    By kermi3 in forum C++ Programming
    Replies: 15
    Last Post: 09-26-2001, 04:16 PM
  3. Homework
    By kermi3 in forum Windows Programming
    Replies: 5
    Last Post: 09-15-2001, 12:48 PM
  4. Homework
    By kermi3 in forum C Programming
    Replies: 0
    Last Post: 09-10-2001, 02:26 PM

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