Hi,
first remark: pls read the "how to's" for that forum , especially how to use code tags </>.
See the URL in my signature about the forum rules.
For your sketch:
- (physically) connect a button to an Arduino pin and GND
- declare that button as input in setup() - preferably as INPUT_PULLUP, so a press will be LOW
- initiate a state variable which holds the most current state of the temperature unit (F or C)
- decide what will be the default unit of measurement at start up, say "F" by
boolean tempUnit = true;
- in loop()
5.1 read the temperature and use the Fahrenheit formula to display the value as long tempUnit is "true"
5.2 continuously read the button, if it is pressed or not including some debouncing
(you could also use some of the debouncing libraries if you don't want to debounce manually) - if a button press was detected, change tempUnit to "false" and use the Celsius formula
You could also use some little switch/case commands to either show the temperature in F or C; in that case I would use an integer variable and initialise with "1" for Fahrenheit and "2" for Celsius.
Then your code would have something like:
switch (tempUnit) {
case 1:
//use the formula for Fahrenheit and display the result as F
break;
case 2:
//use the formula for Celsius and display the result as C
break;
default:
// if nothing else matches, do the default
// default is optional
break;
}