1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include <iostream>
#include <array>
#include <iomanip>
using namespace std;
void printResult(int, int);
void getNumber(int &, int &);
void printResults (int, int)
{
int n, n1;
cout << "You have entered " << n << "and " << n1;
}
void getNumber(int &, int &)
{
// prompts the user for a non-negative number (>= 0)
// reads in the number and check
// keeps re-prompting user if the input is invalid (negative)
// returns the non-negative input
int n, n1;
do
{
cout << "Please enter a non-negative number!\n";
cin >> n >> n1;
}
while (n < 0 && n1 < 0);
return;
}
int main() // Begins Program
{
//Declare Arrays and Pointers
int *arr;
arr = new int[3];
int *x, **y, ***z;
x = arr;
y = &x;
z = &y;
int s1,s2,n,n1;
getNumber( s1, s2 ); // Calls Enter 2 Non Negative Number Function
printResults(n,n1);
//Program Termination
cout << "Program Over\n" << endl;
cout << "Press Enter to end -->" << endl;
char c1, c2; // Variables to store user input
c1 = getchar(); // get first input
c2 = getchar(); // get second input
if (c1 == '\n' && c2 == '\n') // if post inputs are enter
exit(1); // exit
}
|