fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int pin = 1234, enteredPin;
  5. int choice;
  6. float balance = 1000.0, amount;
  7.  
  8. printf("Welcome to ATM\n");
  9. printf("Enter your PIN: ");
  10. scanf("%d", &enteredPin);
  11.  
  12. if (enteredPin != pin) {
  13. printf("Incorrect PIN. Access denied.\n");
  14. return 0;
  15. }
  16.  
  17. do {
  18. printf("\n--- ATM Menu ---\n");
  19. printf("1. Check Balance\n");
  20. printf("2. Deposit Money\n");
  21. printf("3. Withdraw Money\n");
  22. printf("4. Exit\n");
  23. printf("Enter your choice: ");
  24. scanf("%d", &choice);
  25.  
  26. switch (choice) {
  27. case 1:
  28. printf("Current balance: Rs. %.2f\n", balance);
  29. break;
  30.  
  31. case 2:
  32. printf("Enter deposit amount: ");
  33. scanf("%f", &amount);
  34.  
  35. if (amount > 0) {
  36. balance += amount;
  37. printf("Deposit successful. New balance: Rs. %.2f\n", balance);
  38. } else {
  39. printf("Invalid amount.\n");
  40. }
  41. break;
  42.  
  43. case 3:
  44. printf("Enter withdrawal amount: ");
  45. scanf("%f", &amount);
  46.  
  47. if (amount <= 0) {
  48. printf("Invalid amount.\n");
  49. } else if (amount > balance) {
  50. printf("Insufficient balance.\n");
  51. } else {
  52. balance -= amount;
  53. printf("Withdrawal successful. New balance: Rs. %.2f\n", balance);
  54. }
  55. break;
  56.  
  57. case 4:
  58. printf("Thank you for using the ATM.\n");
  59. break;
  60.  
  61. default:
  62. printf("Invalid choice. Please try again.\n");
  63. }
  64. } while (choice != 4);
  65.  
  66. return 0;
  67. }
Success #stdin #stdout 0s 5288KB
stdin
/*  Berechnung des Hamming-Abstandes zwischen zwei 128-Bit Werten in 	*/
/*	einer Textdatei. 													*/
/*  Die Werte müssen auf einer separaten Zeile gespeichert sein			*/
/* 																		*/
/*	Erstellt: 17.5.2010													*/
/*  Autor: Thomas Scheffler												*/

#include <stdio.h>
#include <stdlib.h>

#define ARRAY_SIZE 32

unsigned Hamdist(unsigned x, unsigned y)
{
  unsigned dist = 0, val = x ^ y;
 
  // Count the number of set bits
  while(val)
  {
    ++dist; 
    val &= val - 1;
  }
 
  return dist;
}



int main (void)
{
	char hex;
	int i;
	int a[ARRAY_SIZE];
	int b[ARRAY_SIZE];
	int hamDist = 0;
	FILE* fp;
	
	//Arrays mit 0 initialisieren
	for (i = 0; i < ARRAY_SIZE; ++i)
	{
  		a[i] = 0;
  		b[i] = 0;
	}

	
	fp = fopen("hex.txt","r");
	if (fp == NULL) 
	{
		printf("Die Datei hex.txt wurde nicht gefunden!");
		exit(EXIT_FAILURE);
	}

	i=0;
	printf("1.Zeile einlesen.\n");

 	while((hex=fgetc(fp))!='\n' && hex != EOF)
    {
        a[i]=strtol(&hex,0,16);
		i++;
    }
	i=0;
	printf("2.Zeile einlesen.\n");

 	while((hex=fgetc(fp))!='\n' && hex != EOF)
    {
    	b[i]=strtol(&hex,0,16);
        i++;
    }
	fclose(fp);

	printf("Hamming-Abweichung pro Nibble:\n");
	for (i = 0; i < ARRAY_SIZE; ++i)
	{
		printf ("%i\t%i\t%i\n",a[i],b[i],Hamdist(a[i],b[i]));
		hamDist += Hamdist(a[i],b[i]);
	}
	printf ("\nHamming-Abweichung der Hash-Werte:%d\n",hamDist);
}

stdout
Welcome to ATM
Enter your PIN: Incorrect PIN. Access denied.