2

C++ newbie. Could someone please explain to me what error messages I received mean or why am I getting them? Thank you.

#include <iostream>
#include <string>                                                                                                                            

int main () {
   std::string input;
   double f, k;

   /* edit: codes to go inside the do while loop */                                                                                                                                   
   std::cout << "\nEnter Fahrenheit temperature or 'exit' to end program: "; 
   std::getline(std::cin, input);

   do {
     f = std::atof(input.c_str());  //convert string input to double
     k = (f + 459.67) * (5/9);
     std::cout << "Entered Fahrenheit temperature is: " << f << std::endl;                                                                         
     std::cout << "Temperature in Kelvin is " << k << std::endl << std::endl;

   }while(input != 'exit');  //program runs until input is 'exit'

   return 0;
}

Errors:
t.cc:21:19: warning: multi-character character constant
t.cc: In function `int main()':
t.cc:21: error: no match for 'operator!=' in 'input != 1702390132'

EDIT: Thank you everyone for the advice on while(input != 'exit'). Could someone check that I'm using atof correctly in the calculation section? I'm not getting any calculation with what I have. If I enter 45, I get k = 0 instead or 250.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
user2925557
  • 85
  • 1
  • 3
  • 7

3 Answers3

2

Instead of the multi-character literal that has the type int and an implementation defined value you should use a string literal in this statement

}while(input != 'exit');

That is there must be

}while(input != "exit");
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
0

Use :

while(input != "exit"); // Notice double quotes

'exit' gives "warning: multi-character character constant"

You need to compare it with a string literal using " "

P0W
  • 46,614
  • 9
  • 72
  • 119
0

'a' is a character constant. 'exit' is also a character constant; formally, it's a multi-character character constant. What you want to use here is "exit", which is a string literal.

Pete Becker
  • 74,985
  • 8
  • 76
  • 165