Three Basic C++ Loop Statements Someone Please Help

Three Basic C++ Loop Statements Someone Please Help

I’m just beginning basic programming and need the most basic syntax possible. We’ve only gone as far as loops and here are two example questions I need you to code similarly to. BTW this is a loop lab, so there will be a for, while, etc. loop and maybe an if statement. Please use Visual Studio if possible because that is what we are required to use, but if you can code exactly the same in NetBeans go for it.

 

1.) Write a program to print the following numbers:

5 10 15 20 25 30 35

 

 

#include<iostream>

usingnamespace std;

int main()

{

 

       for (int i = 5; i <= 35; i += 5) {

              cout << i << endl;

       }

       system(“pause”);

 

}

 

 

2.) Write code that will ask the user to input a number between (50-100) and print how many odd & even numbers between that number and 200. 

 

#include<iostream>

usingnamespace std;

int main()

{

       int evens = 0;

       int odds = 0;

       int val = 0;

 

       cout << “Enter a number between 50-100: “ << endl;

       cin >> val;

 

       while (val < 200) {

              if (val % 2 == 1) odds++;

              else evens++;

              val++;

       }

 

       cout << odds << endl;

       cout << evens << endl;

 

       system(“pause”);

 

}

 

 

 

                                 THE REAL QUESTIONS

1.) Write code that will ask the user to input a 4 digit code say “3456” à Drive the user crazy by insisting they entered a wrong code even if they entered the correct code!! After 3 attempts, display a message telling the user you were messing with them! And they are now logged in.

 

2.) 1.     Write code that will print the square roots of the first 25 odd positive integers.For each odd number print the following sentence: The square root of __ is __.

 

3.) Try to run the following program at http://cpp.sh/

 

 #include <iostream>

using namespace std;

int main()

{

      int hour;

int min;

 

      for (hour = 1; hour <= 11; hour++)

      {

            for (min = 0; min <= 59; min++)

            {

                  cout << hour << “:” << min << “AM” << endl;

            }

      }

      system(“pause”);

      return 0;

}

 

1.      What is the bug or logic error in the above program?

2.      Add the lines to fix it.

3.      This is an example of __nested__________ loops.

4.      How many times does the outer loop execute?

5.      How many times does the inner loop execute?

6.      Make the times more accurate by adding lines of code to print seconds.


 

 

"Order a similar paper and get 15% discount on your first order with us
Use the following coupon
"FIRST15"

Order Now