I am writing a program that converts Fahrenheit to Celsius, then after it converts, asks the user if they would like convert another temp until they say no. So I feel I'm on the right track with my program, but after it converts Fahrenheit to Celsius, it does it a second time, then asks if I want to convert again. How can I make it stop from converting a second time and just make it convert once then ask if I want to convert again. It has also been requested specifically that I put the code that asks the user if they want to convert again, in main().
Here is my code:
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
the logic in main is weird.
here is what it says..
getf
convert
loop
getf, but do not convert it
until no
seems like it should be
do
getf
convert f to c
display
prompt to go again
while ()
don't throw code at it to try to fix it. Breaking it down as I did above, into pseudocode of some format that works for you, can make the error stand out so you can see it. Find a way to find the error without changing anything, coding by trial and error will NOT work very often (unfortunately it does work somewhat more frequently for beginner problems, making it tempting early on, but its a bad approach). Other variations on this include rubber duck debugging, playing computer (executing each line on paper by hand as if you were the computer), or taking a fresh piece of paper and stating what you want to do as steps the looking to validate that your code really follows those steps. Find something that works for you, though.
also... I think you are ok for your code, but its a good habit to add decimals to constants that are for doubles, eg /9.0 instead of 9, to avoid accidental integer math.