Posts

Showing posts with the label main loop repeat

C: Calculator with main loop repeat.

Image
Calculator program now loops until user quits. Repl: https://replit.com/@pereiradaniel/Calculator-Main-loop-added Git repo: https://github.com/pereiradaniel/c_programs/blob/master/calc/calc2.c  

C: Character code printout with main loop repeat.

Image
Refactored version of previous program: https://youtu.be/fYuV8NQ1ieo Program loops until user quits. Git repo: https://github.com/pereiradaniel/beginning_c/blob/master/ch4/exercises/4_3/refactor2.c

C: Looped program without using goto statement.

Image
Refactor of Exercise 3-4 without using the goto statement. Git repo: https://github.com/pereiradaniel/beginning_c/blob/master/ch3/exercises/3_4/refactor/refactor.c

C: Modify a calculator program to loop until user quits.

Image
Modify the last example in the chapter that implemented a calculator so that the user is given the option to enter y or Y to carry out another calculation, and n or N to end the program. (Note: You’ll have to use a goto statement for this here, but you’ll learn a better way of doing this in the next chapter.) Git repo: https://github.com/pereiradaniel/beginning_c/blob/master/ch3/exercises/3_4/exercise3_4.c

C: Temperature Conversion With Main Repeat

Image
 https://github.com/pereiradaniel/beginning_c/blob/master/ch3/exercises/3_1/exercise3_1.c // Exercise 3-1 // Write a program that will first allow a user to choose one of two options: // 1. Convert a temperature from degrees Celsius to degrees Fahrenheit. // 2. Convert a temperature from degrees Fahrenheit to degrees Celsius. // The program should then prompt for the temperature value to be entered and output the new value that results // from the conversion. To convert from Celsius to Fahrenheit you can multiply the value by 1.8 and then add 32. #include <stdio.h> #include <ctype.h> #define TOFARENHEIT(a) a*1.8+32.0 #define TOCELSIUS(a) (a-32.0)/1.8 int main(int argc, char* argv[]) { int choice = 0; // Stores user's menu choice. double temp = 0.0; // Stores user's temperature input. char repeat = 'Y'; while (toupper(repeat)=='Y') { choice = 0; while (choice == 0) { printf(...