This repository has been archived on 2023-10-26. You can view files and clone it, but cannot push or open issues or pull requests.
VSMechatronics/Exercises/C8/if_example.c

28 lines
594 B
C
Raw Permalink Normal View History

2022-04-08 15:12:38 +00:00
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
2023-10-03 11:50:05 +00:00
// Declare some variables
int a = 7, b=6;
printf("Enter a value for a: ");
scanf("%d", &a);
printf("Enter a value for b: ");
scanf("%d", &b);
2022-04-08 15:12:38 +00:00
// A single line of code conditional on the value of a
if ( a == 7 )
2023-10-03 11:50:05 +00:00
printf ("The value of a is 7 - so I will do this\n");
2022-04-08 15:12:38 +00:00
// Multiple lines of code conditional on b not equalling 4
// so then need to be placed inside { and }
if ( b != 4 )
{
2023-10-03 11:50:05 +00:00
printf ("The value of b is not 4\n");
printf ("So I will do multiple tasks\n");
2022-04-08 15:12:38 +00:00
}
2023-10-03 11:50:05 +00:00
return 0; // Exit from main
}