SAADQUAMER

Project1.2

Aug 17th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 9.25 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. struct currency
  5. {
  6.     char S1[100];
  7.     float rate;
  8.     int dat;
  9. };
  10.  
  11.  
  12. //edit
  13. void edit()
  14. {
  15.     system("CLS");
  16.     FILE *old,*newrec;
  17.     old=fopen("record.txt","a+");
  18.     newrec=fopen("record.txt","a+");
  19.  
  20.     int test1=0,choice;
  21.  
  22.     char s1[100],s2[100];
  23.     struct currency rt;
  24.     printf("\n\t<<<<<<<<Welcome To Currency Convertion>>>>>>>>");
  25.     printf("\n\n\tEnter Edit Country Name :");
  26.     scanf("%s",&s1);
  27.     {
  28.  
  29.         while(fscanf(old,"%s %f",&rt.S1,&rt.rate)!=EOF)
  30.         {
  31.             if(strcmp(rt.S1,s1)==0)
  32.             {
  33.                 test1++;
  34.                 printf("\n\tCountry :%s\t\t Rate:%.2f",rt.S1,rt.rate);
  35.  
  36.                 printf("\n\nEnter Country New Rate:");
  37.                 scanf("%f",&rt.rate);
  38.                 printf("\t\t Country :%s   rate= %.2f\n\n",rt.S1,rt.rate);
  39.  
  40.                 fprintf(newrec,"\t%s\t\t%.2f\n",rt.S1,rt.rate);
  41.                 printf("Changes saved!");
  42.             }
  43.         }
  44.     }
  45.     fclose(old);
  46.     fclose(newrec);
  47.  
  48.     if(test1==0)
  49.         printf("\n\tRecord not found!!");
  50.  
  51.     printf("\n\nEnter 1 to go to the Admin panel and 2 to Edit Again:");
  52.     scanf("%d",&choice);
  53.  
  54.     if (choice==1)
  55.         admin();
  56.     else if(choice==2)
  57.         edit();
  58.  
  59.  
  60. }//edit
  61.  
  62.  
  63.  
  64. //conversion
  65.  
  66. void conversion()
  67. {
  68.     system("CLS");
  69.     FILE *view;
  70.     int test1=0,test2=0,choice,am;
  71.     float cv,ex,ex1,ex2,temp;
  72.     view=fopen("record.txt","r");
  73.     char s1[100],s2[100],s11[100],s22[100];
  74.     struct currency rt;
  75.     printf("\n\t<<<<<<<<Welcome To Currency Convertion>>>>>>>>");
  76.     printf("\n\t<<<<<<<< Currency Convertion>>>>>>>>");
  77.     printf("\n\n\tEnter Your First Country Name :");
  78.     scanf("%s",&s1);
  79.     {
  80.  
  81.         while(fscanf(view,"%s %f",&rt.S1,&rt.rate)!=EOF)
  82.         {
  83.             if(strcmp(rt.S1,s1)==0)
  84.             {
  85.                 test1++;
  86.                 printf("\n\tCountry :%s\t\t Rate:%.2f",rt.S1,rt.rate);
  87.                 strcpy(s11,rt.S1);
  88.                 ex1=rt.rate;
  89.             }
  90.         }
  91.         fclose(view);
  92.         if(test1==0)
  93.             printf("\n\tRecord not found!!");
  94.     }
  95.     view=fopen("record.txt","r");
  96.     printf("\n\n\tEnter Your Second Country Name :");
  97.     scanf("%s",&s2);
  98.     {
  99.  
  100.         while(fscanf(view,"%s %f",&rt.S1,&rt.rate)!=EOF)
  101.         {
  102.             if(strcmp(rt.S1,s2)==0)
  103.             {
  104.                 test1++;
  105.                 printf("\n\tCountry :%s\t\t Rate:%.2f",rt.S1,rt.rate);
  106.                 strcpy(s22,rt.S1);
  107.                 ex2=rt.rate;
  108.             }
  109.         }
  110.         fclose(view);
  111.         if(test1==0)
  112.             printf("\n\tRecord not found!!");
  113.     }
  114.  
  115.  
  116.     ex=ex1/ex2;
  117.     printf("\n\tEnter Your amount :");
  118.     scanf("%d",&am);
  119.     cv=am*ex;
  120.     if(ex2 > ex1)
  121.     {
  122.         printf("\t%s To %s IS :%.2f\n\n",s22,s11,cv);
  123.     }
  124.     else if(ex2 < ex1)
  125.        { printf("\t%s To %s IS :%.2f\n\n",s11,s22,cv);
  126.  
  127.        }
  128.  
  129.     printf("\n\t Enter 1 to conversion again and 2 to exit :");
  130.     scanf("%d",&choice);
  131.  
  132.     switch(choice)
  133.     {
  134.     case 1:
  135.         conversion();
  136.         break;
  137.     case 2:
  138.         Menu();
  139.         break;
  140.  
  141.  
  142.     }
  143.  
  144.  
  145. }
  146. //conversion
  147.  
  148.  
  149. void search()
  150. {
  151.     system("CLS");
  152.     FILE *view;
  153.     int test=0,choice;
  154.     view=fopen("record.txt","r");
  155.     char s2[100];
  156.     struct currency rt;
  157.     printf("\n\t<<<<<<<<Welcome To Search Option>>>>>>>>");
  158.     printf("\n\n\tEnter Your Country Name :");
  159.     scanf("%s",&s2);
  160.  
  161.     while(fscanf(view,"%s %f",&rt.S1,&rt.rate)!=EOF)
  162.     {
  163.         if(strcmp(rt.S1,s2)==0)
  164.         {
  165.             test++;
  166.             printf("\n\tCountry :%s\t\t Rate:%.2f",rt.S1,rt.rate);
  167.         }
  168.     }
  169.     fclose(view);
  170.     if(test==0)
  171.         printf("\n\tRecord not found!!");
  172.     printf("\n\nEnter 1 to go to the main menu and 2 to Search Again:");
  173.     scanf("%d",&choice);
  174.  
  175.     if (choice==1)
  176.         Menu();
  177.     else if(choice==2)
  178.         search();
  179.     else
  180.     {
  181.         printf("\nInvalid!\a");
  182.  
  183.     }
  184.  
  185.  
  186.  
  187.  
  188. }
  189.  
  190.  
  191. void details()
  192. {
  193.  
  194.     system("CLS");
  195.     FILE *view;
  196.     view=fopen("record.txt","r");
  197.     int test=0,choice;
  198.     struct currency rt;
  199.     printf("\n\tCountry\t\t\tRate\t\t\t\n");
  200.  
  201.     while(fscanf(view,"%s %f",&rt.S1,&rt.rate)!=EOF)
  202.     {
  203.         printf("\n\tCountry :%s\t\t Rate:%.2f",rt.S1,rt.rate);
  204.         test++;
  205.     }
  206.     fclose(view);
  207.  
  208.     if (test==0)
  209.     {
  210.         printf("\nNO RECORDS!!\n");
  211.     }
  212.  
  213. view_list_invalid:
  214.     printf("\n\nEnter 1 to go to the main menu and 2 to exit:");
  215.     scanf("%d",&choice);
  216.  
  217.     if (choice==1)
  218.         Menu();
  219.     else if(choice==2)
  220.         admin();
  221.     else
  222.     {
  223.         printf("\nInvalid!\a");
  224.  
  225.     }
  226. }
  227.  
  228. void add()
  229. {
  230.     system("CLS");
  231.     FILE *currency;
  232.  
  233.     int add,i,choice;
  234.  
  235.     currency = fopen("record.txt","a+");
  236.     printf("\n\t\t\t<<<<<<<<< ADD CURRENCY DATA >>>>>>>>>\n\n");
  237.  
  238.     printf("Enter How Many Country You Want To Add :");
  239.     scanf("%d",&add);
  240.     struct currency rt;
  241.     for(i=1; i<=add; i++)
  242.     {
  243.         printf("%d.Enter Your Country :",i);
  244.         scanf("%s",&rt.S1);
  245.         printf("%d Enter Your Country Rate:",i);
  246.         scanf("%f",&rt.rate);
  247.         printf("\t%d. Country :%s   rate= %.2f\n\n",i,rt.S1,rt.rate);
  248.  
  249.         fprintf(currency,"%s\t\t%.2f\n",rt.S1,rt.rate);
  250.     }
  251.     printf("\nFile is written successfully");
  252.     fclose(currency);
  253.     printf("\n\t\t\t<<<<<< Country added successfully!>>>>>>>");
  254.     printf("\n\n\t\t Enter 1 to go to the Admin Panel and 2 to exit:");
  255.     scanf("%d",&choice);
  256.     switch(choice)
  257.     {
  258.     case 1:
  259.         admin();
  260.         break;
  261.     case 2:
  262.         Menu();
  263.         break;
  264.     }
  265.  
  266. }
  267.  
  268.  
  269. void admin()
  270. {
  271.     system("CLS");
  272.     int choice;
  273.     printf("\n\t<<<<<<<<Currency Conversion Program>>>>>>>>>>>>\n");
  274.     printf("\n\t  <<<<<<<<Welcome To Admin Panel>>>>>>>>>>>>\n\n");
  275.     printf("\t  1) Add Country Information\n");
  276.     printf("\t  2) Edit Country Information\n");
  277.     printf("\t  3) Show Currency Details\n");
  278.     printf("\t  4) Search Country\n");
  279.     printf("\t  5) Money Convertion\n");
  280.     printf("\t  6) Exit To Main Menu\n");
  281.  
  282.  
  283.     printf("\n\t Enter Your Choice (1-6):");
  284.     scanf("%d",&choice);
  285.     switch(choice)
  286.     {
  287.     case 1:
  288.         add();
  289.         break;
  290.     case 2:
  291.         edit();
  292.         break;
  293.     case 3:
  294.         details();
  295.         break;
  296.     case 4:
  297.         search();
  298.         break;
  299.     case 5:
  300.         conversion();
  301.         break;
  302.     case 6:
  303.         Menu();
  304.         break;
  305.     default:
  306.         printf("Invalid Input!!! Input Again...\n");
  307.  
  308.         admin();
  309.  
  310.     }
  311.  
  312.  
  313. }
  314. void user()
  315. {
  316.     system("CLS");
  317.     int choice;
  318.     printf("\n\t<<<<<<<<Currency Conversion Program>>>>>>>>>>>>\n");
  319.     printf("\n\t  <<<<<<<<Welcome To User Panel>>>>>>>>>>>>\n\n\n");
  320.     printf("\t  1) Search Country\n");
  321.     printf("\t  2) Currency Convertion\n");
  322.     printf("\t  3) Show Currency Details\n");
  323.     printf("\t  4) Exit\n");
  324.  
  325.  
  326.  
  327.     printf("\n\t Enter Your Choice (1-4):");
  328.     scanf("%d",&choice);
  329.     switch(choice)
  330.     {
  331.     case 1:
  332.         search();
  333.         break;
  334.     case 2:
  335.         conversion();
  336.         break;
  337.     case 3:
  338.         details();
  339.         break;
  340.     case 4:
  341.         Menu();
  342.         break;
  343.  
  344.     default:
  345.         printf("Invalid Input!!! Input Again...\n");
  346.  
  347.         user();
  348.  
  349.     }
  350.  
  351.  
  352. }
  353. int main()
  354. {
  355.     int bdt=84.30;
  356.     Menu();
  357.     return 0;
  358. }
  359. void Menu()
  360. {
  361.     system("CLS");
  362.     int choice;
  363.  
  364.     printf("\n\t<<<<<<<<Currency Conversion Program>>>>>>>>>>>>\n\n");
  365.  
  366.     printf("\t  <<<<<<<<Welcome To Main Menu>>>>>>>>>>>\n\n");
  367.     printf("\t  1) Admin Login\n");
  368.     printf("\t  2) User \n");
  369.     printf("\n\t Enter Your Choice (1 or 2):");
  370.     scanf("%d",&choice);
  371.     switch(choice)
  372.     {
  373.     case 1:
  374.         pass();
  375.         admin();
  376.         break;
  377.     case 2:
  378.         user();
  379.         break;
  380.     default:
  381.         printf("Invalid Input!!! Input Again...\n");
  382.         Menu();
  383.  
  384.     }
  385.     return 0;
  386. }
  387. int pass(void)
  388. {
  389.     int a=0,i=0;
  390.     char uname[10],c=' ';
  391.     char pword[10],code[10];
  392.     char user[10]="saad";
  393.     char pass[10]="207661";
  394.     do
  395.     {
  396.         system("cls");
  397.  
  398.         printf("\n  ************************** ADMIN LOGIN FORM  **************************  ");
  399.         printf("\n\n                       ENTER USERNAME:-");
  400.         scanf("%s", &uname);
  401.         printf("\n\n                       ENTER PASSWORD:-");
  402.         while(i<10)
  403.         {
  404.             pword[i]=getch();
  405.             c=pword[i];
  406.             if(c==13)
  407.                 break;
  408.             else
  409.                 printf("*");
  410.             i++;
  411.         }
  412.         pword[i]='\0';
  413.  
  414.         i=0;
  415.  
  416.         if(strcmp(uname,user)==0 && strcmp(pword,pass)==0)
  417.         {
  418.             printf("  \n\n\n     <<<<<<<<< WELCOME !!!! LOGIN IS SUCCESSFUL >>>>>>>>>\n\n\n");
  419.             system("PAUSE");
  420.             break;
  421.         }
  422.         else
  423.         {
  424.             printf("\n        <<<<<<<<<SORRY !!!!  LOGIN IS UNSUCESSFUL>>>>>>>>> \n\n");
  425.             a++;
  426.             if (a==3)
  427.             {
  428.                 printf("\nSorry you have entered the wrong username or password for three times!!!");
  429.  
  430.                 Menu();
  431.  
  432.             }
  433.  
  434.             system("PAUSE");
  435.  
  436.  
  437.  
  438.         }
  439.     }
  440.     while(a<=2);
  441.  
  442. }
Advertisement
Add Comment
Please, Sign In to add comment