What are the errors in this code? [closed]
void main (void)
{
char name [2] [30], number [2] [10];
char << "Please type your first name, a blank, and last name) << endl;
cin >> name;
cout << "Name=" <<name << endl;
cout << "Please type a number, press the return key, and another number << endl;
cin >> number [0] >> endl;
cout << number << endl;
}
Too many to mention, but we're not here to act as a homework service. Examine the output of your compiler then tackle them one at a time:
qq.cpp:4:13: warning: missing terminating " character
qq.cpp:4: error: missing terminating " character
qq.cpp:7:13: warning: missing terminating " character
qq.cpp:7: error: missing terminating " character
qq.cpp:1: error: ‘::main’ must return ‘int’
qq.cpp: In function ‘int main()’:
qq.cpp:4: error: expected unqualified-id before ‘<<’ token
qq.cpp:6: error: ‘cout’ was not declared in this scope
qq.cpp:6: error: ‘endl’ was not declared in this scope
qq.cpp:8: error: ‘cin’ was not declared in this scope
At a bare minimum:
- No
using
clause orstd::
prefixes. char
is not a stream.- No closing quotes on some of the string literals.
There is a parenthesis instead of a double quotation mark at the end of "Please type your first name, a blank, and last name)
You don't end the string with a " as in
char << "Please type your first name, a blank, and last name) << endl;
and
cout << "Please type a number, press the return key, and another number << endl;
it should be:
int main (void)
{
char name [2] [30], number [2] [10];
char << "Please type your first name, a blank, and last name)" << endl;
cin >> name;
cout << "Name=" <<name << endl;
cout << "Please type a number, press the return key, and another number" << endl;
cin >> number [0] >> endl;
cout << number << endl;
return 0;
}
char << "Please type your first name, a blank, and last name) << endl;
and
cout << "Please type a number, press the return key, and another number << endl;
are both missing end double quotes
char << "Please type your first name, a blank, and last name)" << endl;
cout << "Please type a number, press the return key, and another number" << endl
精彩评论