Guys I have to deceipher this code but I can't make heads or tails out of it cause it closes the comand window before i can see anything I tried adding a system pause at the end but that just gave me an error.
// Program 6.9: Validate a telephone access code
#include <iostream>
#include <cstdlib>
using namespace std;
// Prototypes for utility functions that main will use
bool Get( istream &in, int &d1, int &d2, int &d3,
int &d4, int &d5 );
bool Valid( int d1, int d2, int d3, int d4, int d5);
int main()
{
int d1;
int d2;
int d3;
int d4;
int d5;
if ( Get( cin, d1, d2, d3, d4, d5 )&&
Valid( d1, d2, d3, d4, d5 ) )
return 0;
else
return 1;
}
bool Get( istream &sin, int &d1, int &d2, int &d3,
int &d4, int &d5 )
{
char c1;
char c2;
char c3;
char c4;
char c5;
if ( sin >> c1 >> c2 >> c3 >> c4 >> c5)
{
if ( isdigit( c1 ) && isdigit( c2 ) && isdigit( c3 ) &&
isdigit( c4 ) && isdigit( c5 ) )
{
d1 = c1 - '0';
d2 = c2 - '0';
d3 = c3 - '0';
d4 = c4 - '0';
d5 = c5 - '0';
return true;
}
else
return false;
}
else
return false;
} // end Get function
bool Valid( int d1, int d2, int d3, int d4, int d5 )
{
if ( d4 == 0 )
return false;
else
return ( ( d1 + d2 + d3 ) % d4 ) == d5;
} // end Valid function
// end code file prog6-9.cpp