Example code:
[spoiler]#include <iostream>
#include <fstream>
#include <string>
#include <windows.h>
using namespace std;
int main()
{
ofstream myFile ("AI.txt");
int age, address;
char selection, character[1];
string name, response;
a:cout<<"Menu:\n9 = Basic Information.\n8 = DATALOG\n7 = Chat.\n0 = Leave\n";
cin>>selection;
switch (selection)
{
case '8' : system("AI.txt notepad.exe");myFile.open("AI.txt");myFile.close();system("CLS");goto a;
case '0' : return 0;
case '9' : goto c;
case '7' : goto e;system ("CLS");
default : cout<<"Nope"<<endl;system ("CLS");goto a;
}
d: cout<<"AI: What is your name?"<<endl;
cin>>name; system ("CLS");
myFile<<"Datalog"<<"\nName: "<<name<<endl;
cout<<"AI: How are you feeling?"<<endl<<name<<": ";
cin>>response; system ("CLS");
if (response == character) {cout<<"Invalid answer";}
myFile<<name<<" is feeling "<<response<<endl;
cout<<"AI: What is your age "<<name<<"?"<<endl<<name<<": ";
cin>>age; system ("CLS");
myFile<<name<<"'s age is "<<age;
myFile.close();
if (! myFile)
{
cout<<"Error";
}
goto a;
c: system ("CLS");cout<<"3";Sleep (1000);system ("CLS");cout<<"2";Sleep (1000);system ("CLS");cout<<"1";Sleep (1000);system ("CLS"); goto d;
e: cout<<system("CLS");
cout<<"Menu:\n9 \n8 \n7 \n6";
cin>>selection;
switch (selection)
{
default : cout<<"Nope"<<endl;system ("CLS");goto a;
}
system ("pause");
}[/spoiler]
[spoiler]#include <iostream>
using namespace std;
int main()
{
int r = 0 , l = 1;
char r0 = 0, l0 = 1, letter = r||l;
e: cout<<"menu = m: ";
c: if (r0 != l0){cin>>letter;}
a: switch(letter)
{
case '0' : cout<<"Right, "<<endl;{goto b;}
case '1' : cout<<"Left, "<<endl;{goto c;}
case 'q' : cout<<"Quit"<<endl;{goto d;}
case 'm' : cout<<"menu\nRight = 0 \nLeft = 1\nQuit = q"<<endl; {goto e;}
default : cout<<"Wrong character!"<<endl;
b: if (r0 != l0){cin>>letter; goto a;}
}
d:
system ("pause");
return 0;
}[/spoiler]
[spoiler]#define DEBUG
#include <iostream>
using namespace std;
#define ASSERT(n)
#define ASSERT(n) \
if(!n) \
{ \
cout<<__TIME__<<endl; \
} \
int main()
{
cout<<"Time: ";
bool flag = 1;
ASSERT (flag != true);
system ("pause");
return 0;
}[/spoiler]
-
C++ is old man. Get with the times. C# is so much prettier.
-
Edited by Malfar: 2/8/2013 4:29:28 AMI agree with Daz, it's best to break up the goto functionallity into actual functions, or better yet the true power of C++ and create a class with methods. I remember a time when a teacher was trying to explain structures and their naming conventions, it always stuck with me because the name of the file was hope2.c. I also remeber using 'goto's because it was how I could convey what needed to be done. You're headed in the right direction, don't give up!
-
Edited by Funkbrotha10: 2/8/2013 4:22:14 AMwhy are you using goto? bad things happen when you try to mix c++ with assembly practices like that
-
I use to do that, then I was like.. Whoa man.. Programming isn't for me.
-
Goto considered harmful. By the way, you tagged this with help, but I don't see any questions.
-
Using "system()" is considered very bad practice.
-
Begone with your schemes!
-
-
Yes! Code to steal!
-
Edited by Miiji: 2/8/2013 2:46:30 AMYou are wasting your time... Destiny awaits you in Mount Kilimanjaro, go, grasshopper. Become the Programmer of Ages!