Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.Suggest one (1) example of a problematic programming situation or scenario tha

ID: 3549233 • Letter: 1

Question

                    1.Suggest one (1) example of a problematic programming situation or scenario that the use or implementation of a loop structure could resolve. Justify your                     response.                 

                    
                


                    




                

                    2.Suggest one (1) example of a problematic programming situation or scenario that the use or implementation of a sequence structure could resolve. Justify your                     response.                 

Explanation / Answer

(1)-->
    Say you have to print number from 1 to 100.. you can use a for loop and print 1 to 100 like this--
            for(int i=1;i<=100;i++)
                cout << i << " ";
    To resolve loop structure, you can use the following code

                #include<iostream>
                using namespace std;

                int main()
                {
                    static int i=1;
                    if(i==101)
                        return 0;
                    cout << i << " ";
                    i++;
                    main();
                }

See I have called the main function itself, and see the use of static keyword here..



(2)-->
    Say you have to print the "Hello" if the number given by user is in between 1 to 20, "Hey" if the number given by user is in between 21 to 40, and say "Bye" if the number given by user is in between 41 to 100..  
        so the pseudo code will be-->
            if(num>0 && num <21)
                print Hello
            else if(num>20 && num <41)
                print Hey
            else if(num>40 && num <101)
                print Bye

So here you see that sequence structure is resolved, the compiler can go to either if or to first else-if or to last else-if, its not sequential