Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- typedef enum { FALSE, TRUE } Boolean;
- Boolean namecheck();
- Boolean lastnamecheck();
- Boolean idcheck();
- void firstoption();
- Boolean agecheck();
- Boolean Isbigletter(char c);
- Boolean Issmallletter(char c);
- Boolean Isnumber(char c);
- Boolean emailcheck();
- Boolean digitcardcheck();
- int firstscreen();
- int main()
- {
- int temp = 0;
- namecheck();
- idcheck();
- temp = firstscreen();
- if (temp == 4)
- return 0;
- else
- if (temp == 1)
- {
- firstoption();
- }
- getchar();
- }
- Boolean namecheck()
- {
- Boolean bool = FALSE;
- char name = 0;
- while (bool == FALSE)
- {
- fflush(stdin);
- printf("Please enter your name\n");
- name = getchar();
- if (Isbigletter(name))
- {
- fflush(stdin);
- name = getchar();
- while (Issmallletter(name))
- {
- fflush(stdin);
- name = getchar();
- }
- if (name == '.')
- {
- return TRUE;
- }
- else
- {
- printf("Invalid character\n");
- }
- }
- else
- {
- printf("Invalid character\n");
- }
- }
- }
- Boolean lastnamecheck()
- {
- Boolean bool = FALSE;
- char name = 0;
- while (bool == FALSE)
- {
- fflush(stdin);
- printf("Please enter your last name\n");
- name = getchar();
- if (Isbigletter(name))
- {
- fflush(stdin);
- name = getchar();
- while (Issmallletter(name))
- {
- fflush(stdin);
- name = getchar();
- }
- if (name == '.')
- {
- return TRUE;
- }
- else
- {
- printf("Invalid character\n");
- }
- }
- else
- {
- printf("Invalid character\n");
- }
- }
- }
- Boolean Isbigletter(char c)
- {
- if ((c > 64) && (c < 91))
- return TRUE;
- return FALSE;
- }
- Boolean Issmallletter(char c)
- {
- if ((c > 96) && (c < 123))
- return TRUE;
- return FALSE;
- }
- Boolean Isnumber(char c)
- {
- if ((c > 47) && (c < 58))
- return TRUE;
- return FALSE;
- }
- Boolean idcheck()
- {
- Boolean bool = FALSE;
- char id = 0;
- int counter = 0;
- while (bool == FALSE)
- {
- fflush(stdin);
- printf("Please enter your ID number\n");
- id = getchar();
- counter++;
- if (Isnumber(id))
- {
- fflush(stdin);
- id = getchar();
- counter++;
- while (Isnumber(id))
- {
- fflush(stdin);
- id = getchar();
- counter++;
- if (counter == 9)
- {
- return TRUE;
- }
- }
- printf("Invalid character\n");
- counter = 0;
- }
- else
- {
- printf("Invalid character\n");
- counter = 0;
- }
- }
- }
- int firstscreen()
- {
- int option = 0;
- int illcount = 1;
- printf("Thank you for choosing SCE Internet Company! How can we help you?\n");
- printf("1) I want to join your company as a new client.\n");
- printf("2) I want to find out some details about my already existing account.\n");
- printf("3) I want to leave your company.\n");
- printf("4) I want to exit the chat.\n");
- scanf_s("%d", &option);
- if ((option > 0) && (option < 5))
- return option;
- while (illcount != 0)
- {
- if (((option < 1) || (option > 4)))
- {
- if (illcount < 3)
- {
- illcount++;
- printf("An illegal option! This is the %d time you chose an illegal option\n", illcount - 1);
- printf("Please retry.\n");
- printf("Thank you for choosing SCE Internet Company! How can we help you?\n");
- printf("1) I want to join your company as a new client.\n");
- printf("2) I want to find out some details about my already existing account.\n");
- printf("3) I want to leave your company.\n");
- printf("4) I want to exit the chat.\n");
- scanf_s("%d", &option);
- }
- }
- if (illcount >= 3)
- {
- illcount++;
- printf("Please come back only when you need something. Have a good day!\n", illcount-1);
- getchar();
- getchar();
- return 4;
- }
- if ((option > 0) && (option < 5))
- {
- illcount = 0;
- return option;
- }
- }
- illcount = 0;
- return option;
- }
- Boolean agecheck()
- {
- Boolean bool = FALSE;
- short age = 0;
- while (bool == FALSE)
- {
- fflush(stdin);
- printf("Please enter your age\n");
- scanf_s("%hd" ,&age);
- if ((age > 17) && (age < 121))
- {
- return TRUE;
- }
- else
- printf("Invalid age\n");
- }
- }
- Boolean emailcheck()
- {
- Boolean bool = FALSE;
- char mail = 0;
- char mailtemp = 0;
- while (bool == FALSE)
- {
- fflush(stdin);
- printf("Please enter your Email address\n");
- mail = getchar();
- if ((mail == '_') || (mail == '.') || (Isnumber(mail)) || (Isbigletter(mail)) || (Issmallletter(mail)))
- {
- fflush(stdin);
- mail = getchar();
- while ((mail == '_') || (mail == '.') || (Isnumber(mail)) || (Isbigletter(mail)) || (Issmallletter(mail)))
- {
- fflush(stdin);
- mail = getchar();
- }
- if (mail == '@')
- {
- fflush(stdin);
- mailtemp = getchar();
- while ((mailtemp == '.') || (Isnumber(mailtemp)) || (Issmallletter(mailtemp)) || (Isbigletter(mailtemp)))
- {
- fflush(stdin);
- mailtemp = getchar();
- }
- if (mailtemp == ' ')
- {
- return TRUE;
- }
- else
- printf("Invalid character\n");
- }
- else
- {
- printf("Invalid character\n");
- }
- }
- else
- {
- printf("Invalid character\n");
- }
- }
- }
- Boolean digitcardcheck()
- {
- Boolean bool = FALSE;
- int digit = 0;
- int temp = 1;
- printf("Enter your 4 last credit card digits\n");
- temp = scanf_s("%d", &digit);
- if (temp != 1)
- printf("Invalid character\n");
- while ((digit < 1000) || (digit > 9999))
- {
- printf("Error! Please enter only the 4 last digits\n");
- temp = scanf_s("%d", &digit);
- }
- return TRUE;
- }
- void firstoption()
- {
- lastnamecheck();
- agecheck();
- emailcheck();
- digitcardcheck();
- printf("Thank you for choosing our company and welcome! Our people will contact you shortly!\n");
- firstscreen();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement