vc++6.0中怎么使用布尔型
/*Program3_7Confusedrecruitionpolicy*/#include<stdio.h>/*#include<stdbool.h>*/intmain...
/*Program 3_7 Confused recruition policy*/
#include <stdio.h>
/*#include <stdbool.h>*/
int main(void)
{
int age=0; /*Age of the applicant*/
int college=0; /*Code for college attended*/
int subject=0; /*Code for subject studied*/
bool interview=false; /*True for accept,false for reject*/
/*Get data on the applicant*/
printf("\nWhat college?1 for Harvard,2 for Yale,3 for other:");
scanf("%d",&college);
printf("\nWhat subject?1 for chemistry,2 for economies,3 for other:");
scanf("%d",&subject);
printf("\nHow old is the applicant?");
scanf("%d",&age);
/*Check out the applicant*/
if((age>25&&subject==1)&&(college==3||college==1))
interview=true;
if(college==2&&subject==1)
interview=true;
if(college==1&&subject==2&&(age<28))
interview=true;
if(college==2&&(subject==2||subject==3)&&age>25)
interview=true;
/*Output decision for interview*/
if(interview)
printf("\n\nGive 'en an interview.");
else
printf("\n\nReject 'em.");
return 0;
}
开始说找不到头文件stdbool.h,我注释掉了以后,错误是bool,false,true都没定义
自己找了个下面的stdbool.h,
/*
stdbool.h
-- Boolean type and values
(substitute for missing C99 standard header)
public-domain implementation from [EMAIL PROTECTED]
implements subclause 7.16 of ISO/IEC 9899:1999 (E)
*/
#ifndef __bool_true_false_are_defined
#define __bool_true_false_are_defined 1
/* program is allowed to contain its own definitions, so ... */
#undef bool
#undef true
#undef false
#if __STDC_VERSION__ < 199901
typedef int _Bool
#endif
#define bool _Bool
#define true 1
#define false 0
#endif /* !defined(__bool_true_false_are_defined) */
错误是
error C2054: expected '(' to follow '_Bool'
error C2085: 'main' : not in formal parameter list
error C2143: syntax error : missing ';' before '{'
敲代码的时候确实变蓝色了,就是通不过编译,难道是vc的问题?
加上using namespace std;也有错误 展开
#include <stdio.h>
/*#include <stdbool.h>*/
int main(void)
{
int age=0; /*Age of the applicant*/
int college=0; /*Code for college attended*/
int subject=0; /*Code for subject studied*/
bool interview=false; /*True for accept,false for reject*/
/*Get data on the applicant*/
printf("\nWhat college?1 for Harvard,2 for Yale,3 for other:");
scanf("%d",&college);
printf("\nWhat subject?1 for chemistry,2 for economies,3 for other:");
scanf("%d",&subject);
printf("\nHow old is the applicant?");
scanf("%d",&age);
/*Check out the applicant*/
if((age>25&&subject==1)&&(college==3||college==1))
interview=true;
if(college==2&&subject==1)
interview=true;
if(college==1&&subject==2&&(age<28))
interview=true;
if(college==2&&(subject==2||subject==3)&&age>25)
interview=true;
/*Output decision for interview*/
if(interview)
printf("\n\nGive 'en an interview.");
else
printf("\n\nReject 'em.");
return 0;
}
开始说找不到头文件stdbool.h,我注释掉了以后,错误是bool,false,true都没定义
自己找了个下面的stdbool.h,
/*
stdbool.h
-- Boolean type and values
(substitute for missing C99 standard header)
public-domain implementation from [EMAIL PROTECTED]
implements subclause 7.16 of ISO/IEC 9899:1999 (E)
*/
#ifndef __bool_true_false_are_defined
#define __bool_true_false_are_defined 1
/* program is allowed to contain its own definitions, so ... */
#undef bool
#undef true
#undef false
#if __STDC_VERSION__ < 199901
typedef int _Bool
#endif
#define bool _Bool
#define true 1
#define false 0
#endif /* !defined(__bool_true_false_are_defined) */
错误是
error C2054: expected '(' to follow '_Bool'
error C2085: 'main' : not in formal parameter list
error C2143: syntax error : missing ';' before '{'
敲代码的时候确实变蓝色了,就是通不过编译,难道是vc的问题?
加上using namespace std;也有错误 展开
3个回答
--
2022-12-05 广告
2022-12-05 广告
图形化编程简单理解为用积木块形式编程,scratch和python也是其中的一种,属于入门级编程,以其简单生动的画面获得无数学生的喜爱,深圳市创客火科技有限公司是一家做教育无人机的公司,旗下有编程无人机,积木无人机及室内外编队,每款飞机含有...
点击进入详情页
本回答由--提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询