Click here to Skip to main content
15,909,193 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is the code it not getting executed more than once plz guide me in this


C++
int y=n,z=0,p;
    int fp;
    int q=0;
     while(q<y)
    {
cout<<"\n SUBSTITUTION TABLE FOR TEACHER:"<<name[pos[q]];
    for(int i=0;i<8;i++)
    {   z=0;
        fp=0;
        p=pos[q];

        if(period[p][i]=="2")
          {
               for(int j=0;j<x;j++)
                if(period[j][i]=="3")
                  {
                  subt[z]=name[j];
                   z++;

                  }
          }
        else
           if(period[p][i]=="4")
           {
              for(int j=0;j<x;j++)
                if(period[j][i]=="5")
                  {
                  subt[z]=name[j];
                   z++;

                  }
           }
           else
              if(period[p][i]=="1")
              {
                 for(int j=0;j<x;j++)
                if(period[j][i]=="0")
                  {
                  subt[z]=name[j];
                   z++;

                  }

              }

      fp=rand()%z+0;
 cout<<"\n period:"<<i+1<<":"<<subt[fp];

    }
    q++;
    }

[edit]Code block added - OriginalGriff[/edit]

What I have tried:

I have tried everything there is no errors in this code, its just not getting executed more than once, its Getting executed only once...
Posted
Updated 23-May-17 13:17pm
v2
Comments
[no name] 23-May-17 10:26am    
Learn how to use the debugger to debug your code.
phil.o 23-May-17 10:26am    
Please format the code.
Richard MacCutchan 23-May-17 11:08am    
There are definitely errors in the code, otherwise it would do what you want. You have also not explained which loop does not get repeated. You could improve the actual readability of the code by using meaningful names for your variables rather than random letters that mean nothing.

Without the rest of your code, we can't do much: we have no idea what is, or should be in pos or name, or even any idea what they are declared as!
As a result, we can;t even run your code fragment under the same conditions you do, so we can't test your code and say "do this".

Fortunately, you have a tool at your disposal which means that you can!
Visual Studio includes a debugger, which lets you take complete control of what is going on, look at variable contents while your code is running, and even execute it one line at a time to see exactly what happens.

So, its going to be up to you.
Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
My best guess is that n=1, you are the only one able to check by using the debugger.

When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.

[Update]
you can start by tooling your code with checkPoints:
At the end of the loop, print the values of q and y.
 
Share this answer
 
v2
Comments
Rithish Áj 23-May-17 23:07pm    
Can i send the full code of it????
Patrice T 24-May-17 4:59am    
You can improve your question with full source code.
But from your other question, only debugger can help you.
Use Improve question to update your question.
[no name] 24-May-17 8:44am    
We aren't a "debug my homework assignment for me" service. Learning how to debug your code is not an optional skill that you can choose not to learn.
Rithish Áj 24-May-17 9:22am    
Sorry guy's i will make a better use of this site

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900