初学C++ 自己编了小程序,大意是询问你是否要回答问题(Y/N)?若Y的话就显示3+3=?答案不论填什么都是GOOD

作者&投稿:左丘会 (若有异议请与网页底部的电邮联系)
初学C++ 自己编了小程序,大意是询问你是否要回答问题(Y/N)?若Y的话就显示3+3=?答案不论填什么都是GOOD~

你少了个大括号,还有你已经定义b为int了,判断时就不用加引号了。正确代码如下:
#include
#include
using namespace std;
int main()
{
char user_1;
int b;
cout << "Do you want to work out the math?(Y/N)"; // 问是否能答题?
cin >> user_1;
if ( user_1 == 'N' || user_1 == 'n')
{
cout << "BYE-BYE";
}
else
{
cout << "3+3=?";
cin >> b;
if ( b == 6)
{ cout << "good";
}
else cout << "no good!";
}
getchar();
}

这个肯定没问题,VS2005亲测。
希望对你有帮助 by fishmin2005

不如输出“MY GOD!"吧,I服了U
#include
main()
{
printf("MY GOD!
");
}
呵呵,开个小玩笑

你少了个大括号,还有你已经定义b为int了,判断时就不用加引号了。正确代码如下:
#include <string>
#include <iostream>
using namespace std;
int main()
{
char user_1;
int b;
cout << "Do you want to work out the math?(Y/N)"; // 问是否能答题?
cin >> user_1;
if ( user_1 == 'N' || user_1 == 'n')
{
cout << "BYE-BYE";
}
else
{
cout << "3+3=?";
cin >> b;
if ( b == 6)
{ cout << "good";
}
else cout << "no good!";
}
getchar();
}

这个肯定没问题,VS2005亲测。
希望对你有帮助 by fishmin2005


宣化县18152648648: 初学C++ 自己编了小程序,大意是询问你是否要回答问题(Y/N)?若Y的话就显示3+3=?答案不论填什么都是GOOD -
长露华舒: 你少了个大括号,还有你已经定义b为int了,判断时就不用加引号了.正确代码如下:#include <string>#include <iostream> using namespace std; int main() { char user_1; int b; cout << "Do you want to work out the math?(Y/N)"; // 问是否能答...

宣化县18152648648: 我是一名初三学生,学了大概4天c++,编了一个简单的程序(完全靠自己),大家看看需要改进什么? -
长露华舒: 你这个还不能算是C++ 没有体现C++的基本特征,也就是面向对象的编程思想 最多就算是C以C++的语句实现 强烈建议你先学习C打好基础 然后再学习C++ 还有 你的main函数在结尾调用自身 很明显的死递归~

宣化县18152648648: 用C++编了一个小程序 -
长露华舒: 你大概是想用char来存储整数是吧 当然是可以的,不过cout默认将char按照ASCLL对应符号输出 这时,在输出前,需要将char转为int 如:cout <<int( ch3) << endl;

宣化县18152648648: 我编写C++的一个小程序.第一步的主要内容是“循环输入两个整数,并输出.其中,输入'|'时退出程序”. -
长露华舒: 输入'|'时退出程序”.这是你希望的.输入| 时退出 while 也可以,没输入| 时再接收 a,b: while (cin>>a && cin>>b){ if (a =='|' || b=='|') break; cout<<"a="<<a<<" , "<<"b="<<b<<"\n"; } cout << "keep_window_open\n"; // 这里做别的事 }

宣化县18152648648: 自学编程,并希望能编出一些小程序和小游戏,比如c++环境下的贪吃蛇等 -
长露华舒: c++ 程序设计和c++ primer这一类只是让你了解语言特性,学会了只能做一些黑窗口程序 ,叫控制台应用 程序 ,没多少人喜欢这个.想做一些小程序的,你要看一下windows程序设计,这个教你做图形化程序,当你把这本书看完的时候,好吧,你已经有做贪吃蛇的基础了,如果你想学,我可以指导你.

宣化县18152648648: C++的一个小程序编写 -
长露华舒: 1、 #include <stdio.h> double fun(int k)//k!的函数 { if (k==1||k==0) return 1; return k*fun(k-1); } void main() { int m,n; double C; do { printf ("请输入m和n: "); scanf ("%d%d",&m,&n); }while(m<n); C=fun(m)/(fun(n)*fun(m-n)); printf("C(m,n)=m!...

宣化县18152648648: 我刚用C++编了个小程序,总是写不好,程序很简单,不到10行代码. -
长露华舒: #include using namespace std; int main() { int n,m,i; cout cin>>n>>m; for(i=n;i if(i%4==0) cout cout return 0; } 这个换掉 for(int n=i;n { cout } 换成 for(int n=i;n { if(n%4==0) cout }

宣化县18152648648: C++编一个小程序,有个不懂帮看下
长露华舒: 修改的地方加了注释,希望对你有所帮助 #include<stdio.h> #include <stdlib.h> main() { int i,j=1,m,n,x,k,z; int a1,b1,c1,d1; int a2,b2,c2,d2; for(z=k;z<2;z++) { j=1; a1=rand()%9+1; b1=rand()%9+1; c1=rand()%9+1; d1=rand()%9+1; printf("欢迎进入...

宣化县18152648648: 初学c++,编写简单程序如下: #include<stdio.h> int main() { printf("hello world!\n"); } -
长露华舒: stdio.h这个是标准c的头文件,你的printf是标准c的io函数,在这个头文件中声明. 而isotream是标准c++的io流,标准c++的io流不是用printf的,而是用流操作符cin和cout. 所以你用printf输出字符串,如果#incllude包含头文件肯定不行,因为这这里没有printf的定义.

宣化县18152648648: c++自编小程序 -
长露华舒: #include <stdio.h> int main(viod) {int a,b;char ch;float c;printf("输入一个式子:");scanf("%d%c%d",&a,&ch,&b);switch(ch){case'+':c=a+b;printf("%d",(int)c);break;case'-':c=a-b;printf("%d",(int)c);break;case'*':c=a*b;...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网