Posted By

A4i on 12/24/11


Tagged

numbers 2 increase decrease Tow


Versions (?)

IncDec2Numbers


 / Published in: C
 

This Code is only for Windows because of getch(); It Increase or Decrease tow number. Depending on which button you press '+' or '-'.

  1. // Only for Windows because of getch();
  2.  
  3. #include <stdio.h>
  4.  
  5. int main()
  6. {
  7. int i, x, y;
  8. char action;
  9.  
  10. Begin:
  11.  
  12. printf("Enter the x: ");
  13. scanf("%d", &x);
  14. getchar();
  15.  
  16. printf("Enter the y: ");
  17. scanf("%d", &y);
  18. getchar();
  19.  
  20. do
  21. {
  22. printf("x, y = %d, %d\n", x, y);
  23. action = getch();
  24. if(action == '+')
  25. {
  26. x++;
  27. y++;
  28. }
  29. else if(action == '-')
  30. {
  31. x--;
  32. y--;
  33. }
  34. }
  35. while((action == '-') || (action == '+'));
  36.  
  37. goto Begin;
  38.  
  39. getchar();
  40. return 0;
  41. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: OdnetninI on September 8, 2012

Version for All systems:

include

int main() { int i, x, y; char action;

Begin:

printf("Enter the x: "); scanf("%d", &x); getchar();

printf("Enter the y: "); scanf("%d", &y); getchar();

do { printf("x, y = %d, %d\n", x, y); scanf("%s", &action); if(action == '+') { x++; y++; } else if(action == '-') { x--; y--; } } while((action == '-') || (action == '+'));

goto Begin;

getchar(); return 0; }

You need to login to post a comment.