1. Engineering
  2. Computer Science
  3. follow the instructions for starting c and viewing the swatthebugs25cpp...

Question: follow the instructions for starting c and viewing the swatthebugs25cpp...

Question details

Follow the instructions for starting C++ and viewing the SwatTheBugs25.cpp file, which is contained in either the Cpp8\Chap10\SwatTheBugs25 Project folder or the Cpp8\Chap10 folder. (Depending on your C++ development tool, you may need to open this exercise’s project/solution file first.) The program should calculate and display the sum of two numbers, but it is not working correctly. Debug the program

Ok so I worked the problem and this is what I came up with but when I run the code it will still not add the numbers, what am I missing.

//SwatTheBugs26.cpp - displays the sum of two numbers
//Created/revised by <your name> on <current date>

#include <iostream>
using namespace std;

//function prototypes
void getNumber(int num);
void calcSum(int n1, int n2, int &n3);

int main()
{
int num1 = 0;
int num2 = 0;
int num3 = 0;

//enter input items
getNumber(num1);
getNumber(num2);


//calculate and display sum
calcSum(num1, num2, num3);
cout << "Sum: " << num3 << endl;

system("pause");
return 0;
} //end of main function

//*****function definitions*****
void getNumber(int num)
{
cout << "Enter a number: ";
cin >> num;
}   //end of getNumber function

void calcSum(int n1, int n2, int &n3)
{
n3 = n1 + n2;
}   //end of calcSum function

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution