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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#include <iostream>
using namespace std;
void peek(char & temp);
void space(void);
void proper(char L_P, char comma, char R_P,
bool & L, bool & C, bool & R);
int main()
{
double x,y;
char L_P, comma, R_P;
bool L, C, R;
while( !L || !C || !R )//fails at the 2 run thru
{//want to continue as long as one or more are false
cout<<"Where is your first point\n";
peek(L_P);
cin>>x;
space();
peek(comma);
cin>>y;
space();
peek(R_P);
proper(L_P, comma, R_P, L, C, R);
}
return 0;
}
void peek(char & temp)
{
if(ispunct(cin.peek()))
{
cin>>temp;
}
else
{
temp=0;
}
return;
}
void space(void)
{
while (isspace(cin.peek()) && cin.peek() != '\n')
{
cin.ignore();
}
return;
}
void proper(char L_P, char comma,
char R_P, bool & L, bool & C, bool & R)
{
if(L_P != '(')
{
cout<<"Left Parenthesis missing.\n";
L=false;
}
else
{
L=true;
}
if(comma != ',')
{
cout<<"Comma is missing.\n";
C=false;
}
else
{
C=true;
}
if(R_P != ')')
{
cout<<"Right Parenthesis missing.\n";
R=false;
}
else
{
R=true;
}
return;
}
|