0
void secimekran() {
  string secim;
  float f, c;
  cout << "c to f or f to c ? " << endl;
  cin >> secim;
  if (secim == "c to f ") {
    cout << "How much celcius" << endl;
    cin >> c;
    ctofah(c);
  } else {
    cout << "how much f";
    cin >> f;
    fahtoc(f);
  }
}

It compiles without error but none of the cin work. Both of them get 0 as default input. Why?

Example:

wlcome c to f or f to c ?
c to f
how much f0 F -17.7778 derece
EMRE DAL
  • 23
  • 6
  • 1
    did you take in count the space after the `f` ? – Ivan Jan 26 '21 at 16:09
  • no can you show it how did you do it – EMRE DAL Jan 26 '21 at 17:24
  • `if (secim == "c to f ")` will not work for several reasons. `cin >> secim;` will read up to the first whitespace character so `"c to f "` will not be in `secim` regardless of what the user typed. Second if you solved that by reading the whole line instead of up to the first whitespace character will your user know to type the space after the f since your if () looks for a space after the f. It would be simpler to ask for `C` or `F` and use a char as the variable (and I mean char not an array / c-string) – drescherjm Jan 26 '21 at 17:47
  • Having access to a debugger like the one in Visual Studio would help a lot in inspecting the variables while the program is running and also understanding why the code behaves as it does instead of having to guess what is going wrong. – drescherjm Jan 26 '21 at 17:53
  • 1
    thank you drescherjm and sorry for late response – EMRE DAL Jan 27 '21 at 20:23

0 Answers0