Thread: i need help for a very hard c programming assignment(for me ) !

  1. #1
    Registered User
    Join Date
    Dec 2018
    Posts
    6

    i need help for a very hard c programming assignment(for me ) !

    Uploadfiles.io - PA4.pdf (pdf file is here). i coded a lot of stuff. the place where the shooter is gonna shoot is ready. but hardest part is to shoot with a direction,explosions etc. i will share my code just to show you that i'm putting effort into that. what i want from you is just to guide me .if you tell me how to write the algorithm i would be grateful. thank you.
    Code:
    #include<stdio.h>
    #include <stdlib.h>
    #include<string.h>
    int r,c,i,j,a=1,b=1,ct=0,m,n;
    char **brick;
    char colour;
    float x,y;
    void printbrick(char **x);
    int main(){
        char command;
        
        scanf("%d %d",&c,&r);
        
        brick=malloc(sizeof(char*)*c);
        for(i=0;i<c;i++){
             brick[i]=malloc(sizeof(char)*r);
                      }                
    
    
      for(i=0;i<r;i++){
            for(j=0;j<c;j++){
                if(i==0&&(j!=0&&j!=c-1)){
                        brick[i][j]='~';}
                else if(j==0|| j==c-1){
                    brick[i][j]='|';}
            else{
              brick[i][j]=' ';
                }
                                   
                          }
        
                        
                        }
        
    
    
        while(scanf("%c",&command)!=EOF){
          
          if(command=='e'||command=='n'||command=='d'){
             ct++;
               if(ct==3){
                  break;}                             }
                                       
          
          if(command=='R'){
                if(brick[a][b]==' '){
                  brick[a][b]='R';
                  b++;             }
                if(brick[a][b]=='|'){
                    b=1;a++;        }
    
    
                   
                                  
    
    
                                  }      
              if(command=='B'){
                if(brick[a][b]==' '){
                  brick[a][b]='B';
                  b++;              }
                if(brick[a][b]=='|'){
                   b=1;a++;         }
                                          
    
    
    
    
    
    
    
    
    
    
                                          }                   
                                                                    
           if(command=='Y'){
                if(brick[a][b]==' '){
                  brick[a][b]='Y';
                  b++;             }
                if(brick[a][b]=='|'){
                b=1;a++;            }
    
    
                                      }
           if(command=='G'){
                if(brick[a][b]==' '){
                  brick[a][b]='G';
                  b++;             }
                if(brick[a][b]=='|'){
                            }
                              }
           if(command==' '){
                if(brick[a][b]==' '){
                  brick[a][b]=' ';
                  b++;             }
                if(brick[a][b]=='|'){
                b=1;a++;            }
    
    
                             
            
                              
                                                                                      
                                         }
    
    
                                       
    
    
                                     }
    
    
        
          scanf("%d %d",&m,&n);
          brick[n][m]='_';
          printbrick(brick);
          while(scanf("%c %f %f",&colour,&x,&y )!=EOF)
          {
    
    
            if(colour='q'){
                break;
                          }
    
    
    
    
    
    
    
    
                                                      }
    
    
                        
                                      
    
    
    
    
        
                  }
                    
      void printbrick(char **x){
             for( i = 0 ;i<r ;i++)
          {
                 for( j = 0 ;j<c ;j++)
              {
                 printf("%c",x[i][j]);
          }
          printf("\n");
        }
    
    
       }
    Last edited by pulsive; 12-22-2018 at 05:00 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well I would suggest you fix your mess of indentation, and write some more functions to break up the overly long main.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2018
    Posts
    6
    Quote Originally Posted by Salem View Post
    Well I would suggest you fix your mess of indentation, and write some more functions to break up the overly long main.
    i don't understand what you're trying to do here and i am not sure if you downloaded the file.i told you that i need you to tell me about how to write the algorithm of the shooting part. but it seems like you like being arrogant and tell people to indent the code which is working and has nothing to do with the part i am stucked with.if you call that help you better choose not to help at all.
    Best regards.

  4. #4
    Guest
    Guest
    Code:
                                 We
    
    
    
                           don't
    
    
    
    
    
    
    
    
        write
    
    
    
                            English
    
    
    
    
              like               
         that
    
    
       
                  either.
    Not that you seem to be too keen on writing well formed written language. If you want help, you need to make it easy for others to help you; nothing arrogant about it. If you don't care about things being orderly, programming won't be your strong suit.

    Start by properly indenting your code, so it's clearly where scopes begin and end. Then we can try to help.

  5. #5
    Registered User
    Join Date
    Dec 2018
    Posts
    6
    Quote Originally Posted by Guest View Post
    Code:
                                 We
    
    
    
                           don't
    
    
    
    
    
    
    
    
        write
    
    
    
                            English
    
    
    
    
              like               
         that
    
    
       
                  either.
    Not that you seem to be too keen on writing well formed written language. If you want help, you need to make it easy for others to help you; nothing arrogant about it. If you don't care about things being orderly, programming won't be your strong suit.

    Start by properly indenting your code, so it's clearly where scopes begin and end. Then we can try to help.
    if i indent the code nothing will change .because i haven't coded the part where i need help yet. i posted the code because i wanted to show that i am asking help for something that i put effort in to.if you download the file and tell me about how i can write the algorithm of the shooting part,i would appreciate it. thank you .

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    I'll start looking at your pdf and code when it doesn't look like something my dog puked up.

    If you still want to be belligerent about it, welcome to my ignore list.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by pulsive
    if i indent the code nothing will change .because i haven't coded the part where i need help yet.
    What you're looking at is an example of technical debt. Technical debt makes it more difficult to fix bugs and add features in the long run. However, getting rid of technical debt does not result in the fixing of a bug or adding of a feature, so sometimes programmers are reluctant to do so, but delaying this for too long will cost you more in the long run. So yes, "nothing will change" if you indent your code, and yet it will: it will make it easier to read, and this will be helpful in the long run.

    In fact, poor indentation is not the only technical debt that you have:
    • Your code has so many variables that lack descriptive names.
    • Your code has so many global variables when it looks like you should have moved them to more local scopes.
    • Your code does not always check the return value of scanf, and when it does, it seems to default to comparing with EOF rather than the number of expected assignments.
    • Your main function probably can be further broken up into smaller functions that each do one thing and do it well.

    You also may have a bug where you used = instead of ==

    Quote Originally Posted by pulsive
    i posted the code because i wanted to show that i am asking help for something that i put effort in to.
    By failing to indent the code properly and then refusing to indent it when told to do so, you demonstrate that you in fact have not put satisfactory effort into your code. If I were your instructor (and I have been an instructor at tertiary level in the past), you would be heavily penalised for turning in code that is so badly formatted.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Registered User
    Join Date
    Dec 2018
    Posts
    6
    Quote Originally Posted by laserlight View Post
    What you're looking at is an example of technical debt. Technical debt makes it more difficult to fix bugs and add features in the long run. However, getting rid of technical debt does not result in the fixing of a bug or adding of a feature, so sometimes programmers are reluctant to do so, but delaying this for too long will cost you more in the long run. So yes, "nothing will change" if you indent your code, and yet it will: it will make it easier to read, and this will be helpful in the long run.

    In fact, poor indentation is not the only technical debt that you have:
    • Your code has so many variables that lack descriptive names.
    • Your code has so many global variables when it looks like you should have moved them to more local scopes.
    • Your code does not always check the return value of scanf, and when it does, it seems to default to comparing with EOF rather than the number of expected assignments.
    • Your main function probably can be further broken up into smaller functions that each do one thing and do it well.

    You also may have a bug where you used = instead of ==


    By failing to indent the code properly and then refusing to indent it when told to do so, you demonstrate that you in fact have not put satisfactory effort into your code. If I were your instructor (and I have been an instructor at tertiary level in the past), you would be heavily penalised for turning in code that is so badly formatted.
    well you are being so harsh on people, i am no expert like you, just a 1st year student with only 2 months experience.i am not a english speaker so i am not sure if i can make myself clear. of course i can indent the code but even if i indent the code my problem wont be solved because i need help for something i haven't coded yet. you are saying something like if you were my instructor or something you would....... . there is an idiom called "putting yourself in someone's shoes" . if i were the instuctor and someone like me were the student i would try to help i wouldn't criticise people like that
    best regards

  9. #9
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    First of all good luck, you're going to really need it.

    Second you really should be worried about this paragraph of your instructions:

    Warning: Any form of code copying, including the copies from the internet, is strictly prohibited. If
    we determine similarities between your codes with any other students in the class, it will be treated
    as cheating and will be punished. So, you would increase the risk of cheating when you see
    somebody else’s code directly or see a solution in the internet (i.e. somebody else might have also
    copied the same code from the internet like you, so both of these codes will be evaluated as copies,
    since they both copy from an external source. Such attempts will always be considered as cheating).
    You are supposed to write the program by yourselves.
    Note: Highlight mine.

    Based on the above, I would say that you should have covered most everything you need to know either in your text book or in the class lectures to complete the assignment.

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by pulsive
    well you are being so harsh on people, i am no expert like you, just a 1st year student with only 2 months experience.
    If you were an expert, then you wouldn't need people to point out these basic points to improve. Not that experts cannot improve their code, but the improvements are unlikely to lie in the areas that I listed. So no, this is not being harsh: this is help for you to take so as to go from a 1st year student with only 2 months of experience to be a better programmer.

    Quote Originally Posted by pulsive
    of course i can indent the code but even if i indent the code my problem wont be solved because i need help for something i haven't coded yet.
    Yes, I understand that. But indent your code anyway! If you cannot do such a simple thing, why should I help you for something that you haven't coded yet? Stop talking and start fixing your code. Then when you come back here and show a better example of what you have done, people would be more inclined to think it worth their while to help you.

    Another thing: I suggest that you post your assignment instructions here in plain text instead, possibly with a few selected images if necessary for illustration. Don't upload it to a third party site where people may be reluctant to download it because it is after all an unknown file.

    Quote Originally Posted by pulsive
    you are saying something like if you were my instructor or something you would....... . there is an idiom called "putting yourself in someone's shoes" . if i were the instuctor and someone like me were the student i would try to help i wouldn't criticise people like that
    Criticism of your code is help: I gave you a laundry list of items that you can improve. If you cannot see the repeated advice for something as routine as indenting your code as help, then you're doomed to fail to improve your programming skills.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    Registered User
    Join Date
    Dec 2018
    Posts
    6
    Quote Originally Posted by laserlight View Post
    If you were an expert, then you wouldn't need people to point out these basic points to improve. Not that experts cannot improve their code, but the improvements are unlikely to lie in the areas that I listed. So no, this is not being harsh: this is help for you to take so as to go from a 1st year student with only 2 months of experience to be a better programmer.


    Yes, I understand that. But indent your code anyway! If you cannot do such a simple thing, why should I help you for something that you haven't coded yet? Stop talking and start fixing your code. Then when you come back here and show a better example of what you have done, people would be more inclined to think it worth their while to help you.

    Another thing: I suggest that you post your assignment instructions here in plain text instead, possibly with a few selected images if necessary for illustration. Don't upload it to a third party site where people may be reluctant to download it because it is after all an unknown file.


    Criticism of your code is help: I gave you a laundry list of items that you can improve. If you cannot see the repeated advice for something as routine as indenting your code as help, then you're doomed to fail to improve your programming skills.
    i see thank you.i will take your advices and pay attention to indentation also from now on i will choose descriptive names for my variables.

  12. #12
    Registered User Kernelpanic's Avatar
    Join Date
    Sep 2018
    Location
    Berlin
    Posts
    105
    That's the second student of a Turkey University who wants to take an exam with help from others. That is not only but also a ridiculing of all other student they are cautious correct.

    That's are characterless and shamefully!

  13. #13
    Registered User
    Join Date
    Dec 2018
    Posts
    6
    Quote Originally Posted by Kernelpanic View Post
    That's the second student of a Turkey University who wants to take an exam with help from others. That is not only but also a ridiculing of all other student they are cautious correct.

    That's are characterless and shamefully!
    watch your mouth. İ haven't done anything to be ashamed of. i never asked someone to do the homework for me . it's just there's a part in the homework i don't understand and i asked for help. if people can tell me about the steps of the algorithm i would appreciate it. i am not asking for any code here. i will write the code by myself.
    and don't waste your time here. go and study some english what kind of sentence is this "That's are characterless and shamefully!" that's are ????? really?? " you don't know me so you are in no position to judge me.

  14. #14
    Registered User
    Join Date
    Dec 2018
    Posts
    38
    Quote Originally Posted by pulsive View Post
    you don't know me so you are in no position to judge me.
    We know you're too lazy and/or stupid to properly format your code. No one is going to help you until you do.

  15. #15
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Op missed "re" from their name given the lack of manners.

    Also, thread going nowhere.

    Messed up code from a messed up individual.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic programming for some but sooo hard for me
    By Boogyman in forum C Programming
    Replies: 18
    Last Post: 02-23-2010, 01:30 AM
  2. Replies: 3
    Last Post: 04-26-2009, 08:54 AM
  3. Hard programming assignment
    By Seiro in forum C Programming
    Replies: 3
    Last Post: 04-13-2006, 07:15 PM
  4. How hard is learning socket programming?
    By BigD in forum Networking/Device Communication
    Replies: 6
    Last Post: 05-03-2004, 02:01 PM
  5. So how hard is programming?
    By Fool in forum C++ Programming
    Replies: 37
    Last Post: 08-25-2001, 09:27 PM

Tags for this Thread