谁能帮我DEBUG一下这几段代码?~

最初由 陪你去看龙卷风 发布
第三个
前2个我没测试,不过编译通过,第三个有点儿意思,我测试了,没问题,不过你没加如果用户输入大于25的话,怎么办。

代码:
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

#include <cstring>

void initialize( char [], int * );
void input( char*, int & );
void print( const char *, const int );
void growOlder( const char [], int * );
bool comparePeople( const char *, const int *,const char *, const int * );

int main()
{
	char name1[ 25 ];
	char name2[ 25 ];
	int age1;
	int age2;

	initialize( name1, &age1 );
	initialize( name2, &age2 );

	print( name1, age1 );
	print( name2, age2 );

	input( name1, age1 );
	input( name2, age2 );

	print( name1, age1 );
	print( name2, age2 );

	growOlder( name2, &age2 );

	if ( comparePeople( name1, &age1, name2, &age2 ) )
	cout << "Both people have the same name and age"
	<< endl;

	return 0;

} // end main

// function input definition
void input( char *name, int &age )
{
	cout << "Enter a name: ";
	cin >> name;
	cout << "Enter an age: ";
	cin >> age;
	cout << endl;
} // end function input

// function initialize definition
void initialize( char name[], int *age )
{
	name = "";
	age = 0;
} // end function initialize

// function print definition
void print( const char name[], const int age )
{
	cout << "The value stored in variable name is: "
	<< name << endl
	<< "The value stored in variable age is: "
	<< age << endl << endl;
} // end function print

// function growOlder definition
void growOlder( const char name[], int *age )
{
	cout << name << " has grown one year older\n\n";
	*age++;
} // end function growOlder

// function comparePeople definition
bool comparePeople( const char *name1, const int *age1, const char *name2, const int *age2 )
{
	return ( age1 == age2 && strcmp( name1, name2 ) );
} // end function comparePeople

你试试不就知道了吗?加了保护的话才是多余的
 
最初由 陪你去看龙卷风 发布
第一个文件
代码:
--------------------Configuration: som - Win32 Debug--------------------
Compiling...
som.cpp
c:\documents and settings\陪你去看龙卷风\desktop\som.cpp(25) : error C2664: 'printDate' : cannot convert parameter 1 from 'int' to 'enum Months'
        Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)
c:\documents and settings\陪你去看龙卷风\desktop\som.cpp(26) : error C2065: 'getYear' : undeclared identifier
c:\documents and settings\陪你去看龙卷风\desktop\som.cpp(27) : error C2065: 'getMonth' : undeclared identifier
c:\documents and settings\陪你去看龙卷风\desktop\som.cpp(28) : error C2065: 'getDay' : undeclared identifier
c:\documents and settings\陪你去看龙卷风\desktop\som.cpp(30) : error C2660: 'validDate' : function does not take 3 parameters
c:\documents and settings\陪你去看龙卷风\desktop\som.cpp(31) : error C2664: 'printDate' : cannot convert parameter 1 from 'int' to 'enum Months'
        Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)
c:\documents and settings\陪你去看龙卷风\desktop\som.cpp(39) : error C2373: 'getMonth' : redefinition; different type modifiers
c:\documents and settings\陪你去看龙卷风\desktop\som.cpp(40) : error C2065: 'Month' : undeclared identifier
c:\documents and settings\陪你去看龙卷风\desktop\som.cpp(40) : error C2146: syntax error : missing ';' before identifier 'myMonth'
c:\documents and settings\陪你去看龙卷风\desktop\som.cpp(40) : error C2065: 'myMonth' : undeclared identifier
c:\documents and settings\陪你去看龙卷风\desktop\som.cpp(48) : error C2373: 'getYear' : redefinition; different type modifiers
c:\documents and settings\陪你去看龙卷风\desktop\som.cpp(55) : error C2373: 'getDay' : redefinition; different type modifiers
c:\documents and settings\陪你去看龙卷风\desktop\som.cpp(56) : error C2562: 'getDay' : 'void' function returning a value
        c:\documents and settings\陪你去看龙卷风\desktop\som.cpp(54) : see declaration of 'getDay'
c:\documents and settings\陪你去看龙卷风\desktop\som.cpp(61) : error C2061: syntax error : identifier 'year'
c:\documents and settings\陪你去看龙卷风\desktop\som.cpp(62) : error C2447: missing function header (old-style formal list?)
c:\documents and settings\陪你去看龙卷风\desktop\som.cpp(120) : error C2082: redefinition of formal parameter 'month'
c:\documents and settings\陪你去看龙卷风\desktop\som.cpp(121) : error C2082: redefinition of formal parameter 'day'
c:\documents and settings\陪你去看龙卷风\desktop\som.cpp(122) : error C2082: redefinition of formal parameter 'year'
Error executing cl.exe.

som.obj - 18 error(s), 0 warning(s)

请你吃麦当劳请定了~

:D
 
这个发帖的挺强,回帖的更强:D
 
我看都看傻了
看来不学这个了 不然就没时间去玩了
 
后退
顶部