#include<iostream>
using namespace std;
int main()
{
int n1,n2,sum;
cout<<"Pls enter 2 number: ";
cin>>n1>>n2;
sum=n1+n2;
cout<<"The sum of "<<n1<<" and "<<n2 <<" is "<<sum<<"\n";
cout<<"program ended\n";
return 0;
}
Convert the program into 4 different functions:
input : reads two numbers
total : sums up the two numbers
dis_total : displays the total
dis_end : displays the ending message
Any global variable not allowed to declare but can use pass by reference to solve the problem.
*/
//what i code
#include <iostream>
using namespace std;
void input(int num1, int num2);
void total(int num1, int num2 ,int* sum);
void display_total(int num1, int num2, int* sum);
void display_end();
int main()
{
int num1, num2, sum; /*end out with error because uninitialized variables num1, num2, and sum. But when i initialized it end up with the number which i initialized #didn't update what user input*/
input(num1, num2);
total(num1, num2, &sum);
display_total(num1, num2, &sum);
display_end();