CYB126-Projects/Homework3/jump_the_five.c
cdez 42fc64e613 Complete HW3
++ Programs
+- C Files
2023-11-05 13:43:22 -07:00

52 lines
1.4 KiB
C

// header files
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
// local constants
/*
Name: Jump the Five
Process: Takes in 7 or 10 numbers, and applies a transformation to the numbers.
Function input/parameters: argc and argv command line parameters
Function output/parameters: NONE
Function output/returned: NONE
Device input/---: NONE
Device output/---: NONE
Dependencies: included by standard libraries
*/
int main(int argc, char *argv[])
{
// define local variables
// do calculations
// check to see if there are valid phone numbers (7 or 10 digits)
if(argc == 8 || argc == 11)
{
// iterate through the arguments in list
for(int i = 1; i < argc; i++)
{
// define and get the number using atoi
int num = atoi(argv[i]);
// check to see if the number is 5/0, and print the opposite.
if(num == 5)
{
printf("0 ");
}
else if(num == 0)
{
printf("5 ");
}
else
{
// otherwise, subtract the number from ten to get "the opposite"
printf("%i ", 10 - num);
}
}
printf("\n");
return 0;
}
printf("You must enter 7 or 10 digits as a valid phone number.\n");
// return success
return 0;
}