开发者

What are the errors in this code? [closed]

It's difficult to开发者_JS百科 tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.
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 or std:: 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜