Tutorial 1 C++

2c.

1.

#include <iostream>

using namespace std;

int main()

{

  int number1, number2, result;

   number1 = 10;

   number2 = 7;

   result = number1 + number2;

   //PAUSES program and waits for user input

   std::cout << “Press Enter to continue”;

   std::cin.get();

   //EXIT program

   return 0;

}

2.

When f8 is pressed the watches box will show the values for number1 then number2 and the combined total of both in results.

3.

After pressing f8 the variables show up as predicted.

4.

Pressing f7 once the breakpoint was reached did two things for me. Firstly, it went down to “return 0;”

Secondly, the yellow arrow disappeared.

3

#include <iostream>

using namespace std;

int main()

{

  int number1, number2, result;

   number1 = 10;

   number2 = 7;

   result = number1 * number2;

   //PAUSES program and waits for user input

   std::cout << “Press Enter to continue”;

   std::cin.get();

   //EXIT program

   return 0;

}

4

#include <iostream>

using namespace std;

int main()

{

    int num1, num2, num3, num4, num5, num6 ;

    num1 = 12;

    num2 = 15;

    num3 = 18;

    num4 = 9;

    num5 = 11;

    num6 = 21;

    int ave = (num1 + num2 + num3 + num4 + num5 + num6) / 6;

    return 0;

}

Design a site like this with WordPress.com
Get started