我正在创建一个游戏,并且我有这段代码。但是,它不起作用:
#include<iostream>
using namespace std;
const int MAX_ITEMS = 100;
bool running = 1;
int playerInfo[2];
void titleFunc();
int userInput = 0;
void newGameFunc();
int main() {
titleFunc();
newGameFunc();
int playerLocation = 0;
while (running) {
}
if (playerLocation == 1) {
cout << "You are in a dungeon. You have just woke up from escaping the execution of your father. You see a pathway to the North, and a large gaping hole to the South.\n";
cout << "1. Go South\n 2. Go North";
cin >> userInput;
if (userInput == 1)
playerLocation = 2;
else
if (userInput == 2)
playerLocation = 3;
}
return 0;
titleFunc() {
cout << "\t\t\t\t---Fantasee---\n\n\n";
cout << "\t\t\t\t 1:Play\n";
cin >> userInput;
if (userInput == 1) {
newGameFunc();
}
else {
running = 0;
}
return;
}
newGameFunc() {
cout << "Welcome to Fantasee, a world of adventure and danger. \n";
cout << "To begin, please enter your gender: \n 1. Male 2. Female";
cin >> userInput;
playerInfo[0] = userInput;
cout << "And what class do you wish to be? \n 1. Wizard 2. Archer 3. Warrior 4. Trickster 5. Knight 6. Assassin";
cin >> userInput;
playerInfo[1] = userInput;
playerLocation = 1;
return;
}
}
}
}
我收到错误消息:
g++ Main.cpp -o Main
Main.cpp: In function ‘int main()’:
Main.cpp:36:17: error: expected ‘;’ before ‘{’ token
Main.cpp:67:1: error: expected ‘}’ at end of input
Edit: Wrong Error Message
Edited code to current.
最佳答案
您在主函数内声明函数体,这是无效的。此外,您使用了过多的 '}'。
您的代码应该更像这样:
#include<iostream>
using namespace std;
const int MAX_ITEMS = 100;
bool running = 1;
int playerInfo[2];
void titleFunc();
int userInput = 0;
int playerLocation = 0;
void newGameFunc();
void titleFunc() {
cout << "\t\t\t\t---Fantasee---\n\n\n";
cout << "\t\t\t\t 1:Play\n";
cin >> userInput;
if (userInput == 1) {
newGameFunc();
}
else {
running = 0;
}
return;
}
void newGameFunc() {
cout << "Welcome to Fantasee, a world of adventure and danger. \n";
cout << "To begin, please enter your gender: \n 1. Male 2. Female";
cin >> userInput;
playerInfo[0] = userInput;
cout << "And what class do you wish to be? \n 1. Wizard 2. Archer 3. Warrior 4. Trickster 5. Knight 6. Assassin";
cin >> userInput;
playerInfo[1] = userInput;
playerLocation = 1;
return;
}
int main() {
titleFunc();
newGameFunc();
while (running) {
}
if (playerLocation == 1){
cout << "You are in a dungeon. You have just woke up from escaping the execution of your father. You see a pathway to the North, and a large gaping hole to the South.\n";
cout << "1. Go South\n 2. Go North";
cin >> userInput;
if (userInput == 1) playerLocation = 2;
else if (userInput == 2) playerLocation = 3;
}
return 0;
}
关于c++ - 在 '{' 标记之前不允许在此处定义函数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22185288/
我正在尝试设置一个puppet节点,但rubygems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由rubygems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
在MRIRuby中我可以这样做:deftransferinternal_server=self.init_serverpid=forkdointernal_server.runend#Maketheserverprocessrunindependently.Process.detach(pid)internal_client=self.init_client#Dootherstuffwithconnectingtointernal_server...internal_client.post('somedata')ensure#KillserverProcess.kill('KILL',
我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢
我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby1.9+ 关于ruby-主要:Objectwhenrun
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re