/* * programming_scanf_delays.c * * Created on: Mar 14, 2023 * Author: johnsontimoj */ //////////////////////////////////////////////// // // Program to practice scanf and delays // // inputs: from user // outputs: some printed statements // //////////////////////////////////////////// // our included libraries #include // provides access to printf() and scanf() #include // provides access to Sleep() // our defined values #define DELAY 2000 // anywhere we put DELAY in our code it is replaced with 2000 // start our main function // format is taken on faith for now // everything between the { } is part of main int main(void){ setbuf(stdout, NULL); // fixes a console bug in eclipse windows // this is taken on faith for now // splash printf("-------------------------------------\n"); printf("This is my program to use scanf and delays\n"); printf("-------------------------------------\n"); printf("\n"); // create a few variables int int_var; float float_var; char char_var; // initialize only char_var char_var = 'G'; // print them - should be garbage for int_var and float_var printf("%i %f %c\n", int_var, float_var, char_var); // initialize or modify our variables by reading in new values // the & in front of the variable names is taken on faith for now printf("Please enter a new int value for int_var: "); scanf("%i", &int_var); printf("Please enter a new float value for float_var: "); scanf("%f", &float_var); printf("Please enter a new char value for char_var: "); // scanf("%c", &char_var); // need to put a space before the % in %c to prevent the previous enter (carriage return) from being used for the character scanf(" %c", &char_var); // print our values // char_val with the %c format prints the character, with the %i format prints the ascii value printf("%i %f %c %i\n", int_var, float_var, char_var, char_var); // print values with text // char_val with the %c format prints the character, with the %i format prints the ascii value printf("int_var is: %i, float_var = %f, and char_var is the character %c with ascii value: %i\n", int_var, float_var, char_var, char_var); // multiple var print // create a delay - Sleep uses mS for its input parameter - 2000 --> 2S // \t in printf() is the tab characters printf("start\t"); Sleep(DELAY); printf("1\t"); Sleep(DELAY); printf("2\t"); Sleep(DELAY); printf("3\n"); // finish up printf("All done!"); // finish our main function with a return for the operating system - taken on faith return 0; }// end main