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;
#include<iostream>
usingnamespace 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.
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.
#include"stdafx.h"
#include <iostream>
int main()
{
longdouble fahrenheit;
longdouble 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.