我的程序在到达"cin << ans1 "时崩溃
My Program crashes when it reaches "cin << ans1 "
该程序在到达cin >> ans1;
时实际上崩溃。 我用atom
编写了这段代码,但我在code::blocks
中尝试了相同的程序,它运行良好。我的atom
编译器有问题吗...
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
string name[30];
string gender;
int age;
void Job()
{
printf("To apply for Job, Plz Enter your name: ");
getline(cin, name[20]);
printf("Enter Your Gender: ");
cin >> gender;
printf("Enter your age: ");
cin >> age;
printf("n");
while (age > 100)
{
printf("Enter a real age Dumbass: ");
cin >> age;
}
return;
}
int main(int argc, char const *argv[])
{
Job();
char ans1;
printf("n");
printf("Entered Information is...n");
cout << "Name: " << name[20] << " " << "Sex: " << gender << endl;
cout << "Age: " << age;
printf("Is this Correct?(y/n): ");
cin >> ans1;
if (ans1 == 'y')
{
if (age < 60 && age > 14 )
{
printf("It seems that you are eligible to vote...n");
printf("Go to our Website to Sign up...n"); /* code */
}
else
{
printf("Sorry... But you are not Eligable to be hired...n");
}
}
else
{
while(ans1 != 'y')
{
printf("Write again...n");
Job();
}
}
return 0;
}
首先,将ans1 != y
放在 while 循环中没有任何意义,因为ans1
不会改变,也不会发生任何新情况,请尝试使用它
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
string name[30];
string gender;
int age;
void Job()
{
printf("To apply for Job, Plz Enter your name: ");
getline(cin, name[20]);
printf("Enter Your Gender: ");
cin >> gender;
printf("Enter your age: ");
cin >> age;
printf("n");
while (age > 100)
{
printf("Enter a real age Dumbass: ");
cin >> age;
}
return;
}
void h()
{
Job();
char ans1;
printf("n");
printf("Entered Information is...n");
cout << "Name: " << name[20] << " " << "Sex: " << gender << endl;
cout << "Age: " << age;
printf("Is this Correct?(y/n): ");
cin >> ans1;
if (ans1 == 'y')
{
if (age < 60 && age > 14 )
{
printf("It seems that you are eligible to vote...n");
printf("Go to our Website to Sign up...n"); /* code */
}
else
{
printf("Sorry... But you are not Eligable to be hired...n");
}
}
else
{
if(ans1 != 'y')
{
printf("Write again...n");
h();
}
}
}
int main()
{
h();
}
相关文章:
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 呼叫运营商<<临时
- 如何防止clang格式在流运算符调用之间添加换行符<<
- <<操作员在下面的行中工作
- 如何显式调用运算符<<
- 我的程序在到达"cin << ans1 "时崩溃
- 模板操作员&lt;未打电话
- C / CUDA中的模板方法是3个角括号(&lt;&lt;&lt;)
- C - 创建矢量&lt; vector&lt; double&gt;&gt;矩阵具有分配而不是inizializ
- 错误:调用"std::vector<:vector<int>>::p ush_back(std::vector<std::__cxx11::basic_string<
- C 建造者Clang STD :: Sill,找不到超载的操作员&lt;
- 为什么STD :: MAP需要操作员&lt;以及我如何写一个
- 为什么“操作员”需要const但不是为“运营商&lt;”
- 为什么将此对向量&lt; map&lt; int,int&gt;&gt;中的地图进行更新.失败
- C :对矢量进行排序&lt; struct&gt;(结构有2个整数)基于结构的整数之一
- 明确的专业化“ CheckIntmap&lt;&gt;”实例化
- 什么是模板&lt;&gt;inline bla bla
- 左角支架解释为操作员&lt;而不是模板参数
- 编辑C Qlist&lt; object*&gt; gt;QML代码和一些QML警告中的模型
- 超载操作员&lt;&lt; - 必须是二进制操作员