Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- struct currency
- {
- char S1[100];
- float rate;
- int dat;
- };
- //edit
- void edit()
- {
- system("CLS");
- FILE *old,*newrec;
- old=fopen("record.txt","a+");
- newrec=fopen("record.txt","a+");
- int test1=0,choice;
- char s1[100],s2[100];
- struct currency rt;
- printf("\n\t<<<<<<<<Welcome To Currency Convertion>>>>>>>>");
- printf("\n\n\tEnter Edit Country Name :");
- scanf("%s",&s1);
- {
- while(fscanf(old,"%s %f",&rt.S1,&rt.rate)!=EOF)
- {
- if(strcmp(rt.S1,s1)==0)
- {
- test1++;
- printf("\n\tCountry :%s\t\t Rate:%.2f",rt.S1,rt.rate);
- printf("\n\nEnter Country New Rate:");
- scanf("%f",&rt.rate);
- printf("\t\t Country :%s rate= %.2f\n\n",rt.S1,rt.rate);
- fprintf(newrec,"\t%s\t\t%.2f\n",rt.S1,rt.rate);
- printf("Changes saved!");
- }
- }
- }
- fclose(old);
- fclose(newrec);
- if(test1==0)
- printf("\n\tRecord not found!!");
- printf("\n\nEnter 1 to go to the Admin panel and 2 to Edit Again:");
- scanf("%d",&choice);
- if (choice==1)
- admin();
- else if(choice==2)
- edit();
- }//edit
- //conversion
- void convertion()
- {
- system("CLS");
- FILE *view;
- int test1=0,test2=0,choice;
- view=fopen("record.txt","r");
- char s1[100],s2[100];
- struct currency rt;
- printf("\n\t<<<<<<<<Welcome To Currency Convertion>>>>>>>>");
- printf("\n\n\tEnter Your First Country Name :");
- scanf("%s",&s1);
- {
- while(fscanf(view,"%s %f",&rt.S1,&rt.rate)!=EOF)
- {
- if(strcmp(rt.S1,s1)==0)
- {
- test1++;
- printf("\n\tCountry :%s\t\t Rate:%.2f",rt.S1,rt.rate);
- }
- }
- fclose(view);
- if(test1==0)
- printf("\n\tRecord not found!!");
- }
- printf("\n\n\tEnter Your Second Country Name :");
- scanf("%s",&s2);
- {
- while(fscanf(view,"%s %f",&rt.S1,&rt.rate)!=EOF)
- {
- if(strcmp(rt.S1,s2)==0)
- {
- test1++;
- printf("\n\tCountry :%s\t\t Rate:%.2f",rt.S1,rt.rate);
- }
- }
- fclose(view);
- if(test1==0)
- printf("\n\tRecord not found!!");
- }
- }
- //conversion
- void search()
- {
- system("CLS");
- FILE *view;
- int test=0,choice;
- view=fopen("record.txt","r");
- char s2[100];
- struct currency rt;
- printf("\n\t<<<<<<<<Welcome To Search Option>>>>>>>>");
- printf("\n\n\tEnter Your Country Name :");
- scanf("%s",&s2);
- while(fscanf(view,"%s %f",&rt.S1,&rt.rate)!=EOF)
- {
- if(strcmp(rt.S1,s2)==0)
- {
- test++;
- printf("\n\tCountry :%s\t\t Rate:%.2f",rt.S1,rt.rate);
- }
- }
- fclose(view);
- if(test==0)
- printf("\n\tRecord not found!!");
- printf("\n\nEnter 1 to go to the main menu and 2 to Search Again:");
- scanf("%d",&choice);
- if (choice==1)
- Menu();
- else if(choice==2)
- search();
- else
- {
- printf("\nInvalid!\a");
- }
- }
- void details()
- {
- system("CLS");
- FILE *view;
- view=fopen("record.txt","r");
- int test=0,choice;
- struct currency rt;
- printf("\n\tCountry\t\t\tRate\t\t\t\n");
- while(fscanf(view,"%s %f",&rt.S1,&rt.rate)!=EOF)
- {
- printf("\n\tCountry :%s\t\t Rate:%.2f",rt.S1,rt.rate);
- test++;
- }
- fclose(view);
- if (test==0)
- {
- printf("\nNO RECORDS!!\n");
- }
- view_list_invalid:
- printf("\n\nEnter 1 to go to the main menu and 2 to exit:");
- scanf("%d",&choice);
- if (choice==1)
- Menu();
- else if(choice==2)
- admin();
- else
- {
- printf("\nInvalid!\a");
- }
- }
- void add()
- {
- system("CLS");
- FILE *currency;
- int add,i,choice;
- currency = fopen("record.txt","a+");
- printf("\n\t\t\t<<<<<<<<< ADD CURRENCY DATA >>>>>>>>>\n\n");
- printf("Enter How Many Country You Want To Add :");
- scanf("%d",&add);
- struct currency rt;
- for(i=1; i<=add; i++)
- {
- printf("%d.Enter Your Country :",i);
- scanf("%s",&rt.S1);
- printf("%d Enter Your Country Rate:",i);
- scanf("%f",&rt.rate);
- printf("\t%d. Country :%s rate= %.2f\n\n",i,rt.S1,rt.rate);
- fprintf(currency,"%s\t\t%.2f\n",rt.S1,rt.rate);
- }
- printf("\nFile is written successfully");
- fclose(currency);
- printf("\n\t\t\t<<<<<< Country added successfully!>>>>>>>");
- printf("\n\n\t\t Enter 1 to go to the Admin Panel and 2 to exit:");
- scanf("%d",&choice);
- switch(choice)
- {
- case 1:
- admin();
- break;
- case 2:
- Menu();
- break;
- }
- }
- void admin()
- {
- system("CLS");
- int choice;
- printf("\n\t<<<<<<<<Currency Conversion Program>>>>>>>>>>>>\n");
- printf("\n\t <<<<<<<<Welcome To Admin Panel>>>>>>>>>>>>\n\n");
- printf("\t 1) Add Country Information\n");
- printf("\t 2) Edit Country Information\n");
- printf("\t 3) Show Currency Details\n");
- printf("\t 4) Search Country\n");
- printf("\t 5) Exit\n");
- printf("\n\t Enter Your Choice (1-6):");
- scanf("%d",&choice);
- switch(choice)
- {
- case 1:
- add();
- break;
- case 2:
- edit();
- break;
- case 3:
- details();
- break;
- case 4:
- search();
- break;
- case 5:
- Menu();
- break;
- default:
- printf("Invalid Input!!! Input Again...\n");
- admin();
- }
- }
- void user()
- {
- system("CLS");
- int choice;
- printf("\n\t<<<<<<<<Currency Conversion Program>>>>>>>>>>>>\n");
- printf("\n\t <<<<<<<<Welcome To User Panel>>>>>>>>>>>>\n\n\n");
- printf("\t 1) Search Country\n");
- printf("\t 2) Currency Convertion\n");
- printf("\t 3) Show Currency Details\n");
- printf("\t 4) Exit\n");
- printf("\n\t Enter Your Choice (1-4):");
- scanf("%d",&choice);
- switch(choice)
- {
- case 1:
- search();
- break;
- case 2:
- convertion();
- break;
- case 3:
- details();
- break;
- case 4:
- Menu();
- break;
- default:
- printf("Invalid Input!!! Input Again...\n");
- user();
- }
- }
- int main()
- {
- Menu();
- return 0;
- }
- void Menu()
- {
- system("CLS");
- int choice;
- printf("\n\t<<<<<<<<Currency Conversion Program>>>>>>>>>>>>\n\n");
- printf("\t <<<<<<<<Welcome To Main Menu>>>>>>>>>>>\n\n");
- printf("\t 1) Admin Login\n");
- printf("\t 2) User \n");
- printf("\n\t Enter Your Choice (1 or 2):");
- scanf("%d",&choice);
- switch(choice)
- {
- case 1:
- pass();
- admin();
- break;
- case 2:
- user();
- break;
- default:
- printf("Invalid Input!!! Input Again...\n");
- Menu();
- }
- return 0;
- }
- int pass(void)
- {
- int a=0,i=0;
- char uname[10],c=' ';
- char pword[10],code[10];
- char user[10]="saad";
- char pass[10]="207661";
- do
- {
- system("cls");
- printf("\n ************************** ADMIN LOGIN FORM ************************** ");
- printf("\n\n ENTER USERNAME:-");
- scanf("%s", &uname);
- printf("\n\n ENTER PASSWORD:-");
- while(i<10)
- {
- pword[i]=getch();
- c=pword[i];
- if(c==13)
- break;
- else
- printf("*");
- i++;
- }
- pword[i]='\0';
- i=0;
- if(strcmp(uname,user)==0 && strcmp(pword,pass)==0)
- {
- printf(" \n\n\n <<<<<<<<< WELCOME !!!! LOGIN IS SUCCESSFUL >>>>>>>>>\n\n\n");
- system("PAUSE");
- break;
- }
- else
- {
- printf("\n <<<<<<<<<SORRY !!!! LOGIN IS UNSUCESSFUL>>>>>>>>> \n\n");
- a++;
- if (a==3)
- {
- printf("\nSorry you have entered the wrong username or password for three times!!!");
- Menu();
- }
- system("PAUSE");
- }
- }
- while(a<=2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement