Lucy Damon
/
Damon_A1_1_switch
Finalized Code for Assignment 1: Lucy Damon
main.cpp
- Committer:
- lucydamon
- Date:
- 2022-09-27
- Revision:
- 0:412654635bad
File content as of revision 0:412654635bad:
#include "mbed.h" //Lucy Damon Assignment 1 //The purpose of this assignment is to utilize a for loop to activate different cases. Serial pc(USBTX, USBRX); DigitalOut myled(LED1); int main() { float a; for (int n=1; n<6; n++) { //==> [(i=1) initialization] [(i++)= i+1)] [i<6 = loop condition/stop condition] as long as i is less than 6, it will execute this for loop. a = (float) n; switch (n) { case 1: pc.printf("a=%f ; minimum\r\n",a);//code to be executed if n=1 wait(2); break; case 2: pc.printf("a=%f ; low\r\n",a);//code to be executed if n=2 wait(2); break; case 3: pc.printf("a=%f ; medium\r\n",a);//code to be executed if n=2 wait(2); break; case 4: pc.printf("a=%f ; high\r\n",a);//code to be executed if n=2 wait(2); break; case 5: pc.printf("a=%f ; maximum\r\n",a);//code to be executed if n=2 wait(2); break; default: pc.printf("you failed the assignment\r\n");//code to be executed if n doesnt match above statements } } }