Please hep me with this problem: I am having a problem with string handling using c language. This is actually an assignment.
Here's how the whole program must work:
1. User must input a valid password
2. Once the user inputted a valid password, it will access to an employee's database
3. After the user's identity is confirmed, it will display the employee's current status at work (name, position, employee's ID NO. and Net salary) and will ask the user whether to change employee's net salary or not.
4. The computation for net salary continues once the user decided to proceed the process of changing the employee's net salary.
5. After computing, it will display the new data for the employee and will ask again to change the employee's net salary.
I am almost done with this assignment but I'm still not contented for I want the password to be in Char Datatype. Of course, it is obvious that users might not know that the password must be in numbers. So I prefer it to make it string but in C, there is no such thing as a String Datatype. I have to use char datatype to be able to use strings.
I want the program to accept char variables when entering a valid password.
I am using Dev C++ for this program.
Here's the main problem in my program that I wanted to change:
long int password[7]={11201993}; // valid password
AND
if (password[7] !=11201993)
**If you have other suggestions, please let me know, too. Thank you :)**
This is the whole coding of my program:
#include <stdio.h> #include <stdlib.h> void design_one(); //function dispaying design void db__intro(); //function displaying intro message void sal(double); //function displaying computed net salary and other computations main() { char execute; // for database execution double Net_sal; //for net sal() function long int password[7]={11201993}; // valid password int d; // for net sal execution // design_one(); // printf ("Welcome to Jem's Database! In order to access her files,\n\t \t\tyou need to enter a valid password!"); printf("\n\n\tProceed to enter database? (y/n): "); scanf ("%c", &execute); //user decides whether to execute database or not switch(execute) { case 'y': case 'Y': //if user decided to enter the database printf ("\n\tPassword? : "); repeat://input locztion for goto scanf ("%i", &password[7]); //user must input password if (password[7] !=11201993) { printf ("\n\tInvalid password! Please type the correct one: "); goto repeat;//while password is not correctly entered, it will keep asking for a password } //if password is correctly entered, it will proceed to the database else { system ("cls"); db__intro(); // shows database intro while (d != 0)//while user does not exit database { printf("\n\tEnter command = "); scanf("%i", &d); if (d == 0) { exit(0);// program shut down } if (d==1) { sal(Net_sal);//displays the new database } else//If command is incorrectly entered, it will automatically shut the program { system ("cls"); printf("\n\n\n\tPROGRAM MALFUNCTIONED due to program error! Program shutting down.\n\t\t"); system ("pause"); exit(0); } } } break; //if user decides to not continue to the database case 'n': case 'N': exit(0);// pause the program for a while then proceed to exit. break; //automatic exit default: // if user incorrectly inputted a wrong command, the program will automatically shut down system ("cls"); printf ("\n\n\n\tSystem error due to invalid input of command! Program shutting down! \n\t"); system ("pause");// pause the program for a while then proceed to exit. exit(0); break; } getch(); } // Upper design; void design_one() { int i, j; printf ("|"); for (i=0; i<=77; i++) { printf ("-"); } printf ("|\n\n\n\t"); } //displays database intro void db__intro() { printf("\n\n\tUSER IDENTITY CONFIRMED! LOADING USER DATA..\n\t"); system ("pause"); system ("cls"); design_one(); printf("\n\n\tName: Jemimah Beryl M. Sai\tUser ID NO. 310-0384\n\tNet Salary: 30000 Php\t\tCurrent Position: Software Engr."); printf ("\n\n\tPRESS 1 - Change employee's net salary\n\tPRESS 0 - Exit database \n"); } //computation for net salary of employee void sal (double ns) { int w_hrs,w_days, otime; double w_pay, hr_rate, taxr, taxc; printf("\tAmount of hourly rate: "); scanf ("%lf", &hr_rate); printf("\tNumber of working hours: "); scanf("%i", &w_hrs); printf("\tNumber of working days: "); scanf ("%i", &w_days); printf("\tNumber of over timed hours: "); scanf("%i", &otime); printf("\tTax Rate:\t"); scanf("%lf", &taxr); system ("cls"); w_pay = (((w_hrs+otime)*hr_rate)*w_days);//weekly pay computation taxc = w_pay*(taxr/100);//convert tax rate to decimal ns=w_pay-taxc;//net salary computation design_one(); printf("\n\n\tName: Jemimah Beryl M. Sai\tUser ID NO. 310-0384"); printf("\n\tNet Salary: %.2lf Php\t\tCurrent Position: Software Engr.", ns); printf ("\n\n\tWeekly Pay: %.2lf Php", w_pay); printf("\n\tHourly Rate: %.2lf Php/hour", hr_rate); printf("\n\tWorking Hour(s): %i hours", w_hrs); printf("\n\tOvertime Hour(s): %i hours", otime); printf("\n\tWorking Days: %i days", w_days); printf("\n\tTax rate: %.1lf percent\n", taxr); return ; }