Thread: I can't seem to find where is my mistake

  1. #1
    Registered User
    Join Date
    Nov 2020
    Posts
    8

    I can't seem to find where is my mistake

    I made code for my ordering system assignment. When I executed it and tried to order 2, the order details doesnt store my first choice of order as well as the price for it. I can't post my code here to avoid plagiarism so I am thinking of sending the code via pm if thats okay.

  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
    > I can't post my code here to avoid plagiarism
    Well you're pretty much stuffed then.

    If you're worried that others will steal your work, you have the benefit of being able to show "mine is original, because I can log in and show I'm the original author".

    On the other hand, if you're the thief and you're trying to hide that fact, then no one here is interested in helping cheats.
    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
    Nov 2020
    Posts
    8
    It’s just that I’m afraid if my lecturer gonna cut my marks without asking if it’s originally mine

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Like I said, you can prove you're the original poster - so what's to worry about?

    Unless your assignment is meant to be closed book and seeing help online is not allowed.

    Raise your concerns with the lecturer to find out what the rules are.
    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.

  5. #5
    Registered User
    Join Date
    Nov 2020
    Posts
    8
    Alright, I’ll try to ask my lecturer if it’s okay. I’ll get back to you soon after he replied

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Presumably this assignment is a full blown class project, not some test question that asks for a small snippet of code for an answer. Therefore, it will probably be fairly big as far as code posted in online forums go.

    What you can do is to simplify the code: post the smallest and simplest compilable program that demonstrates the problem. You'll thus be cutting out all the other stuff that's part of the assignment but not immediately relevant to the problem.

    Along with putting some identifying detail in a comment (e.g., your name or student ID), this makes it so that any of your classmates seeing this post wouldn't be able to copy it without adapting it anyway, and you can prove to your teacher that it is yours. And of course, you would be making it easier for members here to diagnose and help you fix the problem, and you might even do that yourself in the process.
    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

  7. #7
    Registered User
    Join Date
    Nov 2020
    Posts
    8
    My lecturer said that it is not advisable to post it so I will try to edit some text in the code before posting it. Hold on

  8. #8
    Registered User
    Join Date
    Nov 2020
    Posts
    8
    Code:
    #include <stdio.h>
    
    int main ()
    {
        int i;                                                                                 
        int x;                                                                                 
        int j;                                                                                 
        int k;                                                                             
        int ne;                                                             
        int ye;                                                                     
        int nug;                                                         
        int wae[x];                                                                 
        int wacri[x];                                                             
        int fflar[x];                                                            
        int nextfg[x];                                                            
        float wprice[x];                                                                
        float pricefg;                                                            
        float sum;                                                                            
        float cost;                                                                        
        char typewae [3][10] = {"Ame","Bel","Rol"};                    
        char cri [2][10] = {"cpy","sft"};                                
        char flafg [4][20] = {"Kay","But","Ch","Bbry"};                 
        
        i = 1;
        j = 1;
        k = 1;
        pricefg = 1.20;
        
        printf("\nHow many wae to order?\n");
        scanf("%d", &ne);
        
        do{                                                                                    
            A : 
            printf("\nWae %d : \n", i);
            printf("\nWtype of wae you like?\n");
            printf("1 - Ame Wae\n2 - Bel Wae\n3 - Rol Wae\n");
            scanf("%d", &wae[x]);                                                
            
            switch(wae[x])
            {
                case 1 :                                                                
                {
                    B :
                        printf("\nWould you like it cpy or sft?\n");
                        printf("1 - cpy\n2 - sft\n");
                        scanf("%d", &wacri[x]);
                        if(wacri[x]==1)
                        {
                            wprice[x] += 12.00;    
                        }
                        else
                        {
                        if(wacri[x]==2)
                            wprice[x] += 10.00;
                        
                        else
                        {
                        goto B;
                        }
                        }
                        break;
                }
                
                case 2 :                                                                    
                {
                    C :
                    printf("\nWould you like it cpy or sft?\n");
                    printf("1 - cpy\n2 - sft\n");
                    scanf("%d", &wacri[x]);
                    if(wacri[x]==1)
                    {
                        wprice[x] += 16.00;
                    }    
                    else
                    {
                    if(wacri[x]==2)
                        wprice[x] += 14.00;
                        
                        else
                        {    
                            goto C;
                        }
                    }
                    break;
                }
                
                case 3 :                                                                    
                {
                    D :
                    printf("\nWould you like it cpy or sft?\n");
                    printf("1 - cpy\n2 - sft\n");
                    scanf("%d", &wacri[x]);
                    if(wacri[x]==1)
                    {
                        wprice[x] += 14.00;
                    }    
                    else
                    {
                    if(wacri[x]==2)
                        wprice[x] += 12.00;
                        
                        else
                        {
                            goto D;
                        }
                    }
                    break;
                }
                            
                default :                                                                    
                {
                    goto A;
                }
            }
            
            E :
            printf("\n1 - Kay\n2 - But\n3 - Ch\n4 - Bbry\n");
            printf("Please choose your fg.\n");                                                                    
            scanf("%d", &fflar[x]);
            
            if(fflar[x]>=5 || fflar[x]<=0)                                        
            {
                goto E;
            }
            
            F :
            printf("\nWould you like to add an addfg?\n");                
            printf("1 - Y\n2 - N\n");
            scanf("%d",&ye);
            
            switch(ye)
            {
                case 1 :                                                                    
                    {
                    printf("\nHow many would you like to add?\n");                                                                
                    scanf("%d",&nug);
                    
                    G :
                    do                                                                            
                    {
                    printf("\nExtra Fg %d : \n",j);
                    printf("1 - Kay\n2 - But\n3 - Ch\n4 - Bbry\n");                            
                    scanf("%d",&nextfg[x]);
                    
                    if(nextfg[x]>4 || nextfg[x]<0)                                    
                    {
                        goto G;
                    }
                    j++;
                    }while(j<=nug);
                    break;
                    }
                case 2 :                                                                        
                {
                    break;
                }
                default :                                                                        
                {
                    goto F;
                }
                    
            }
        if(nug>=1)
        wprice[x] += (nug*pricefg);                                    
        
        i++;
        }
        while(i<=ne);
        
        printf("\nOrder Details : \n");
        printf("\nTotal Wae order : %d \n", ne);
    
    
        for(i=1 ; i<=ne; i++)                                                    
        {
            printf("\nWae %d : \n",i);
            printf("Type: ");
            printf(typewae[wae[x]-1]);
            printf(" (");
            printf(cri[wacri[x]-1]);
            printf(")");
            
            printf("\nFg : ");
            printf(flafg[fflar[x]-1]);
            
            for(k=1 ; k<=nug; k++)
            {
                printf("\naddfg %d: ",k);
                printf(flafg[nextfg[x]-1]);
    
    
            }
            
            printf("\nTotal: %.2f \n",wprice[x]);                                                
            cost += wprice[x];
        }
        printf("\nTotal Order : %.2f \n",cost);                                                    
    
    
        return 0;
    }

  9. #9
    Registered User
    Join Date
    Nov 2020
    Posts
    8
    Sorry in advanced if it sounded weird

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Before you go further, there are a few things that you do or take note of:
    • Break up your program into smaller, well-named functions that each does one thing and does it well. This makes it easier to understand your code because it becomes possible to understand discrete parts of your code, and then understand them when they are put together, instead of trying to understand one long piece of code all at once.
    • Get rid of your use of the goto keyword. As you increase in knowledge of C programming, you will find that there are uses for goto that are pretty reasonable, but right now it looks like you're tempted to use it even when there's a better solution, e.g., many of your current uses of goto can be replaced by loop constructs, and others look like they could be replaced by function calls.
    • You have made some attempt at indentation, but you can be more consistent. This becomes especially important when you have nested levels of code blocks within a function, otherwise it becomes more difficult to trace the flow of control through your code.
    • You should be aware that given a variable x, this declares a variable length array with x elements:
      Code:
      int wae[x];
      If you don't set x to a known value before this point, then the variable length array will be declared with some garbage number of elements, possibly resulting in undefined behaviour if the value of x happens to be negative.
    • If wae is declared as having x number of elements, then &wae[x] results in undefined behaviour because you're accessing the array out of bounds. It doesn't look like you set x to an initial value anywhere.
    Last edited by laserlight; 11-16-2020 at 02:55 AM.
    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
    Nov 2020
    Posts
    8
    -Alright, I will try to break it up into a smaller programs.
    -Replacing my goto with loop- I'll try to change that too.
    -I'm not sure which one do you mean by indentation? It could be because I'm only into my fifth week of learning in this course.
    -I thought I should be putting the code that way for it to work since my friend did it well that way and he got the code running right.
    -Oh, I understand. I will remove that as well.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can`t find mistake in this code
    By AidenK in forum C Programming
    Replies: 4
    Last Post: 05-25-2016, 12:59 PM
  2. sily mistake...cant find it!
    By brack in forum C Programming
    Replies: 2
    Last Post: 02-28-2011, 03:29 PM
  3. Find my mistake!
    By kacey in forum C Programming
    Replies: 4
    Last Post: 02-03-2011, 03:10 AM
  4. Find my mistake!
    By kacey in forum C Programming
    Replies: 2
    Last Post: 02-02-2011, 08:36 PM
  5. Can not find my mistake in this code?
    By BLG in forum C Programming
    Replies: 2
    Last Post: 09-04-2009, 04:19 PM

Tags for this Thread