So i decided my first program is going to be a text game. I have the basic part done, i just can't get the string working. What i want it to do, is
1) user inputs their name
2) name is stored under the "name" string
3) name is then printed to the screen
I don't really know what i'm doing with strings, but i compared my strings to the dogsim game someone posted on the games forum and they looked the same.
My output is:Code:#include <iostream> #include <windows.h> #include <stdlib.h> #include <string> using std::cin; using std::cout; using std::string; unsigned long int money; unsigned short int reputation; unsigned short int time_worked; unsigned short int skill; string name; string hospital name; string state; string country; void start(); void instruction(); void begin(); void yourstats(); void gamemenu(); void work(); void buyitem(); void sellitem(); void patientdied(); void patientgotwell(); void paycheck(); void bills(); void fired(); void hired(); void sued(); void gameover(); void start() { cout<<"Welcome to Doctor Sim v1!"\n\n; cout<<"Main Menu"\n; cout<<"1)Begin Simulation"\n; cout<<"2)Instruction"\n"; cout<<"3)Exit"\n; cin>>mainmenuchoice; cin.ignore(); if (mainmenuchoice == "1") { begin(); } else if (mainmenuchoice == "2") { instruction(); } else if (mainmenuchoice == "3") { } else { cout<<"Wrong Answer! Simulation will now begin!"\n\n; begin(); } void instruction() { cout<<"What is there to explain? Follow the promts and get money! boink"\n; start(); } void begin() { string name; name = "Doctor"; cout<<"Hello, are you here to apply for the job?"; cin>>answer1; cin.ignore(); if (answer1 == "yes") { cout<<"good"; } else if (answer1 == "no") { cout<<"That's too bad, you look like a fine doctor. I think you should see the hospital manager anyway."; } cout<<"Hello, you must be the doctor I heard about. We're looking for a another doctor to hire, so let's preceed to the interview."; cout<<"First, what's your name?"; cin>>name; cout<<"Let me write this down...Name:" << name << ", what college did you goto?"; cout<<"Really..."; cin>>; cout<<"Well, i'll hire you, but only on a trial basis. You screw up and you're gone."; } int main() { start(); }
These errors seem simple, but everything seems right to me. I don't understand why it's only the name string that i get an error on. And i'm not too sure on how to end a program (error 2). I just thought i needed a bracket and that was it.Code:Compiling... main.cpp D:\programming\code\my code\learning project\main.cpp(15) : error C2146: syntax error : missing ';' before identifier 'name' D:\programming\code\my code\learning project\main.cpp(15) : fatal error C1004: unexpected end of file found Error executing cl.exe. main.exe - 2 error(s), 0 warning(s)
Any help would be appreciated. Thanks.



LinkBack URL
About LinkBacks



