Temp conversion fahrenheit to celcius

I am just trying to learn Visual C++ and in this class to get us started we were given a code that was our first program to compile and link in the Visual C++ 2010 Express Edition. I have typed in the code and tried to run and debug it and it has thrown back some errors that I am not quite sure what to do to fix them. Can someone take a look and offer a little help?

This is what I am working with:

#include"stdafx.h"
#include"conio.h"
#include<iostream>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
double fahrenheit;
double celsius;
char test_char;

//Get the temperature in fahrenheit
cout << "Enter the temperature in fahrenheit: ";
cin >> fahrenheit;

//Convert the temperature to celsius
celsius = (fahrenheit-32) / 1.8;

//Display the temperature in celsius
cout << "The temperature in celsius is " << celsius << endl;

cout << "Enter any character to exit";
cin >> test_char;

return 0;
}

Last edited on
Alway include you code between tags like this;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream>

using namespace std;

int main(int argc,  char *argv[]) {
       double fahrenheit;
	double celsius;

	//Get the temperature in fahrenheit
	cout << "Enter the temperature in fahrenheit: ";
	cin >> fahrenheit;

	//Convert the temperature to celsius
	celsius = (fahrenheit-32) / 1.8;

	//Display the temperature in celsius
	cout << "The temperature in celsius is " << celsius << endl;

        return 0;
}


Your code works, stripped from what M$ expects, so to get any help you'd have to include what error message VC is giving you.
The error code that I was getting is:

Severity Code Description Project File Line Suppression State
Error C2679 binary '>>': no operator found which takes a right-hand operand of type 'const char [11]' (or there is no acceptable conversion) TempConverter c:\users\student\documents\visual studio 2015\projects\tempconverter\tempconverter\tempconverter.cpp 29

I was getting 3 error messages earlier but solved those and now when I try and run it I get this message.
Improved, simpler, more portable for your program.
To make it even better you could split your program into functions that do individual things.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include"stdafx.h"
#include <iostream>

int main()
{
long double fahrenheit;
long double celsius;

//Get the temperature in fahrenheit
std::cout << "Enter the temperature in fahrenheit: ";
std::cin >> fahrenheit;

//Convert the temperature to celsius
celsius = (fahrenheit-32) / 1.8;

//Display the temperature in celsius
std::cout << "The temperature in celsius is " << celsius << std::endl;

std::cout << "Press any key to exit...";
std::cin.ignore();

return 0;
}


You can replace std::cin.ignore(); with std::cin.ignore(numeric_limits<streamsize>::max(), '\n') to make it better but it does not work in all IDE's and doesn't work every time for some reason. To use std::cin.ignore(numeric_limits<streamsize>::max(), '\n') you have to use #include <limits> but this doesn't work every time.
Last edited on
Thanks for your help I was able to use the advice given and finished the assignment ....

I appreciate everyone's help so much.
Topic archived. No new replies allowed.