login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > Overige > C en C++ > C++ - Rekenmachine

C++ - Rekenmachine

Auteur: barry - 30 september 2004 - 19:27 - Gekeurd door: Dennisvb - Hits: 4260 - Aantal punten: 3.33 (6 stemmen)




Een grappige rekenmachine in C++
Ik heb windows.h geïnclude, waardoor ik tekst in kleur kan zetten voor een leuk uiterlijk 

Bekiek 'm moar! 

Code:
  1. #include <iostream.h>
  2. #include <windows.h>
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <iomanip.h>
  6. #include <string.h>
  7.  
  8. int main()
  9. {
  10. int keuze;
  11. long num1;
  12. long num2;
  13. char count;
  14. long som;
  15. char yesno;
  16.  
  17. menu:
  18. system("cls");
  19.  
  20.  
  21.  
  22. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN);
  23. cout << "1. Rekenmachine" << endl;
  24. cout << "2. Afsluiten" << endl;
  25.  
  26. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_GREEN);
  27. cout << "Maak uw keuze: " << endl;
  28. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_RED);
  29. cout << "--> ";
  30. cin >> keuze;
  31. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN);
  32. system("cls");
  33. if(keuze==1){ goto calculator; }
  34. if(keuze==2){ goto exit; }
  35. else {
  36. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_RED);
  37. cout << "Ongeldige invoer!" << endl;
  38. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN);
  39. cerr << "Press any key to continue";
  40. getchar();
  41. goto menu; }
  42.  
  43. calculator: //########### REKENMACHINE!!
  44. system("cls");
  45.  
  46. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN);
  47.  
  48. cout << "Getal1: ";
  49. cin >> num1;
  50.  
  51. cout << "Getal2: ";
  52. cin >> num2;
  53.  
  54. cout << "Berekening (*, +, - of /):";
  55. cin >> count;
  56. system("cls");
  57. if(count=='*'){ som = num1 * num2; }
  58. if(count=='-'){ som = num1 - num2; }
  59. if(count=='/'){ som = num1 / num2; };
  60. if(count=='+'){ som = num1 + num2; }
  61.  
  62. cout << "Uitkomst:" << endl;
  63. cout << num1 << " " << count << " " << num2 << " = " << som << endl << endl;
  64.  
  65. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_GREEN);
  66.  
  67. cout << "Wilt u nog een berekening maken?" << endl << "[Y/N]: ";
  68. cin >> yesno;
  69. if(yesno=='y'){ goto calculator; }
  70. if(yesno=='n'){ goto menu; }
  71. else { goto confirm_calc; }
  72.  
  73. confirm_calc:
  74. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_RED);
  75. cout << endl << endl << endl << "Ongeldige invoer!" << endl;
  76.  
  77. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_GREEN);
  78. cout << "Wilt u nog een berekening maken?" << endl << "[Y/N]: ";
  79. cin >> yesno;
  80. if(yesno=='y'){ goto calculator; }
  81. if(yesno=='n'){ goto menu; }
  82. else { goto confirm_calc; } //########### REKENMACHINE!!
  83.  
  84.  
  85. return 0;
  86. }
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (4)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.027s