I want the user to assign a value for int temp1 and int temp2. However, the compiler is saying I need to initialise one of the two variables (temp2).
Why is it only asking me to initialise temp2 and not temp1? When I do assign a value to temp2 the program then ignores whatever value the user enters.
Is my code sloppy and if so, is there a way I can fix this?
(I've included the whole program in case it is relevant however the error i'm receiving is in the inputDetails() function.)
#include <iostream>
using namespace std;
//Prototype
void inputDetails(int* n1, int* n2);
void outputDetails(int num1, int num2, int* pNum, int* n1, int* n2, int** ppNum);
//Functions
int main()
{
int num1;
//num1 pointer
int* n1 = &num1;
int num2;
//num2 pointer
int* n2 = &num2;
//get pNum to point at num1
int* pNum;
pNum = new int;
*pNum = num1;
//pointer to pNum
int** ppNum = &pNum;
//call functions
inputDetails(n1, n2);
outputDetails(num1, num2, pNum, n1, n2, ppNum);
//change pNum to point at num2
delete pNum;
pNum = new int;
*pNum = num2;
//call function again
outputDetails(num1, num2, pNum, n1, n2, ppNum);
delete pNum;
system("PAUSE");
return 0;
}
void inputDetails(int* n1, int* n2)
{
int temp1, temp2;
cout << "Input two numbers" << endl;
cin >> temp1, temp2;
*n1 = temp1;
*n2 = temp2;
}
void outputDetails(int num1, int num2, int* pNum, int* n1, int* n2, int** ppNum)
{
cout << "The value of num1 is: " << num1 << endl;
cout << "The address of num1 is: " << n1 << endl;
cout << "The value of num2 is: " << num2 << endl;
cout << "The address of num2 is: " << n2 << endl;
cout << "The value of pNum is: " << pNum << endl;
cout << "The dereferenced value of pNum is: " << *pNum << endl;
cout << "The address of pNum is: " << ppNum << endl;
}