-
an error
Code:
//after a long time, i figured this out
#include <iostream>
using namespace std;
int main()
{
double ans1;
int x;
cout<<"Hi there! I am PC, the computer. What's your name?:" << endl;
cout<<"Hi " <<endl;
cout<<"Game?:";
cin >>x;
if(x==1)
{
cout<<"All right! Ok... This is a questionaire! You answer correctly,
"you move on. 1 question. 1st question:"<<endl<<endl;
cout<<"What is 398+276?: "<<endl;
cin>>ans1;
if(ans1==674)
{
cout<<"That is correct!!!";
}
else
{
cout<<"Wrong!";
}
}
cin.get();
return 0;
}
the compiler says that line #15 has errors. that line is the first cout. it says missing terminating "character
what the heck am i missing here.
-
The error I get is on line 21, the first cout inside the if. It is because your string doesn't have a trailing " on that line. Your string can span two lines, but you must have both lines in their own quotes, or use a forward slash to continue to the next line and remove the quote there.
-
If your compiler supports it, you can attempt to do what you are doing by putting a '\' at the end of the above line. But its best to do as jlou suggested as all compilers accept:
Code:
"multi"
"-"
"line"
" "
"strings like this"
-
i moved a " away, then it works fine
Code:
#include <iostream>
using namespace std;
int main()
{
double ans1;
int x;
cout<<"Hi there! I am PC, the computer. What's your name?:" << endl;
cout<<"Hi " <<endl;
cout<<"Game?:";
cin >>x;
if(x==1)
{
cout<<"All right! Ok... This is a questionaire! You answer correctly,
you move on. 1 question. 1st question:"<<endl<<endl;
cout<<"What is 398+276?: "<<endl;
cin>>ans1;
if(ans1==674)
{
cout<<"That is correct!!!";
}
else
{
cout<<"Wrong!";
}
}
cin.get();
return 0;
}