1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
/* Simplest of all calculators project */
#include <stdio.h>
int get_menu(choice);
float add(float x, float y);
float sub(float x, float y);
float mult(float x, float y);
float div(float x, float y);
int main (void)
{
float x;
float y;
float z;
int choice=get_menu(choice); /* this should get number ranging 1-5 representing user's choice and perform the correct calculation */
while (choice !=5) /* if this is TRUE then goes to the first if ... correct? */
/* if FALSE this does not execute at all and jumps to line 70 ...correct? */
{
if (choice == 1) /* if this is TRUE executes the statements and when the block "{...}" finishes goes to line 70: printf() ... correct? */
/* if FALSE goes to next if */
{
printf("\nEnter the first number : ");
scanf("%f", &x);
printf("\nEnter the second number : ");
scanf("%f", &y);
z=add(x,y);
printf("%f plus %f equals %f", x, y, z);
}
if (choice == 2) /* if this is TRUE executes the statements and when the block "{...}" finishes goes to line 70: printf() ... correct? */
/* if FALSE goes to next if */
{
printf("\nEnter the first number : ");
scanf("%f", &x);
printf("\nEnter the second number : ");
scanf("%f", &y);
z=sub(x,y);
printf("%f minus %f equals %f", x, y, z);
}
if (choice ==3) /* if this is TRUE executes the statements and when the block "{...}" finishes goes to line 70: printf() ... correct? */
/* if FALSE goes to next if */
{
printf("\nEnter the first number : ");
scanf("%f", &x);
printf("\nEnter the second number : ");
scanf("%f", &y);
z=mult(x,y);
printf("%f times %f equals %f", x, y, z);
}
if (choice == 4) /* if this is TRUE executes the statements and when the block "{...}" finishes goes to line 70: printf() ... correct? */
/* if FALSE where does program execution go? */
{
printf("\nEnter the first number : ");
scanf("%f", &x);
printf("\nEnter the second number : ");
scanf("%f", &y);
z=div(x,y);
printf("%f divided by %f equals %f", x, y, z);
}
}
printf("\nExiting...");
return 0;
}
/*Functions used in my program*/
int get_menu(void)
{
int sel=0;
do
{
puts("1: +");
puts("2: -");
puts("3: *");
puts("4: /");
puts("5: EXIT");
puts("select :");
scanf("%d", &sel);
}
while (sel<1 || sel>5); /* while sel<1 || sel>5 == 0 FALSE this goes to return statement, otherwise goes back to the do keyword...correct? */
return sel;
}
float add(float x, float y)
{
float z;
z=x+y;
return z;
}
float sub(float x, float y)
{
float z;
z=x-y;
return z;
}
float mult(float x, float y)
{
float z;
z=x*y;
return z;
}
float div(float x, float y)
{
float z;
z=x/y;
return z;
}
|