C++ variables:
OK here it goes. First, C++ and JS are VERY different. In JS variables are defined with var <variable name> = something here;
. The nice thing about Js is that it figures out the data-type of variables automatically without you having to explicitly write it, while the reverse is the case in C++ where you have to write it yourself. For example, for an integer you would use int x = 10;
and for a string you would use string hello = "world";
(However you will need to add the string library to be able to do this).
Now for the C++ code fix:
You are doing several things wrong. I would personally try to learn the basics of C++ and then restart, but that is just me. First thing that is wrong:
1)You need to have #
before you include.
2) You need to put the curly braces just after you start your function (this is the same in JS).
3) you need to define your variables the way I described above.
4) Don't use commas in cout.
5) You need to have quotes around your text
7) You need to have semicolon after every line of code.
here is an example of how you could fix your code:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string myName = "Ravi" ;
string foodType = "Apple" ;
int numberEaten = 3 ;
cout << myName << "ate" << numberEaten << foodType ;
return 0;
}