Defining matricies

This is a discussion on Defining matricies within the C++ Programming forums, part of the General Programming Boards category; Yes this is for my homework. I am not lazy getting other people to do it for me i am ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    13

    Defining matricies

    Yes this is for my homework.
    I am not lazy getting other people to do it for me i am just stuck.

    This is the code i have. It sux and has too many errors to even list the errors on my compiler.

    I am trying to create two functions to define the x,y and z co-ordinates of a line at its two ends, and store them in a matrix.

    Very boring and difficult as I'm new to ++ but my talents lie elsewhere.

    Someone who is good with ++ would probably be able to sort this code out in a second.

    So someone please help me if anyone feels like it.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    
    {
    
       double line[2][3];                                        
       double x,y;
    
       int menu_option;
       
       printf("Please choose from the menu\n\n");               
       
       printf("1.\t\tTranslate the line\n");                     
       printf("2.\t\tScale the line\n");                         
       printf("3.\t\tRotate the line\n");
       printf("4.\t\tChange position of L0 (Where P=0)\n");
       printf("5.\t\tChange position of L1 (Where P=1)\n");
       printf("6.\t\tEvaluate a point on the line\n");
       printf("7.\t\tExit the program\n\n");
                                  
       printf("Enter your choice here\n\n\n");
       scanf("%lf", &menu_option);                               
       printf("\n\n\n"); 
    
    } 
    
    //Function defining 1st point of array
    
    { 
       
       void enteringp1(int [0][0], int [0][1], int [0][2]);
       printf("Please enter the set of co-ordinates for the first point, P1, separated by spaces.\n\n");
       scanf("%lf %lf %lf", &[0][0] &[0][1] &[0][2]); 
       printf("\n\nThe co-ordinates for the first point, P1 are\t\t %lf,  %lf,  %lf\n\n" [0][0] [0][1] [0][2]);
    
    }  
    
      //Function defining 2nd of the array 
    
    {  
      
       void enteringp2(int [1][0], int[1][1], int [1][2]);
       printf("Please enter the set of co-ordinates for the second point, P2, seperated by spaces.\n\n");
       scanf("%lf %lf %lf", &[1][0] &[1][1] &[1][2]);
       printf("\n\nThe co-ordinates for the second point, P2 are\t\t %lf,  %lf,  &lf\n\n" [1][0] [1][1] [1][2]);
    
    }

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,062
    This is C not C++. Since that's out of the way, I'll edit this and answer your questions.

    First off you must prototype your functions above main. This is so the compiler knows what they can handle when they see the calls in main.

    Second, you need the calls in main. There is no point in making a function if you aren't gonna use them.

    Third, when you define a function, you don't put the name in the function, it goes before the open brace, like main()

    Code:
    void enteringp1(int array1[2][2], int array2[2][2], int array3[2][2]) { 
       printf("Please enter the set of co-ordinates for the first point, P1, separated by spaces.\n\n");
       scanf("%lf %lf %lf", array1[0][0], array2[0][1], array3[0][2])
       printf("\n\nThe co-ordinates for the first point, P1 are\t\t %lf,  %lf,  %lf\n\n" 
        array1[0][0], array2[0][1], array3[0][2]);
    }
    Next your have to give names to your array variables, you can't just use random indexes. They need a variable to store the location in memory. I changed that in the above example. You also can't define an array size of 0. That doesn't really make any sense, does it.

    Next you have to seperate your arguements by commas in your functions like printf() and scanf().

    You know I gotta tell you the truth. From the way this code looks, I'd say you spent more time sleeping in your class than paying attention.
    Last edited by SlyMaelstrom; 12-02-2005 at 01:04 PM.
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    One of the things you need to learn when programming is to test stuff that isn't working by writing another program to play around with just a few lines of code. For instance, since you have so many errors, it might be helpful to see if you are even able to create an array and assign it some values and then display the values. There's no point in writing a function that deals with 2d arrays if you aren't even able to declare one and assign it a few values and have that work.

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    13
    Thanks guys thats alot of help.

    If it is C and not C++ then our lecturer must be stupider than I thought. He has been teaching it as ++, and although I suck at it I have been doing what he has been teaching us.

    But if he teaches us the wrong code then what hope have I got. So have I really been spending more time sleping than paying attention???

  5. #5
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,062
    Well let me put it this way... show your teacher the code you posted... if he doesn't see a problem with it, put a note in to the principle of your school to have that teacher fired.
    Sent from my iPadŽ

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Almost all C code is also legal C++ code, so technically that could be considered C++ as well. However, it is C code, and C++ is very different language with different tools and different techinques, so if your instructor is teaching you that code as C++, then you aren't learning proper C++.

  7. #7
    Registered User
    Join Date
    Nov 2005
    Posts
    13
    Well we knew he was crap anyway.
    Don't even think he is a proper lecturer either, just a 3rd year undergrad who was drafted in at the last minute.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Defining derivated class problem
    By mikahell in forum C++ Programming
    Replies: 9
    Last Post: 08-22-2007, 02:46 PM
  2. Defining const in a class
    By g4j31a5 in forum C++ Programming
    Replies: 5
    Last Post: 11-20-2006, 10:27 AM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  4. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM

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