PDA

View Full Version : For those of you who like C++ and Football:



oudavid1
12/22/2011, 07:18 PM
I made this :D

I would love for someone to find any flaws with it (because there are some).

I am really bored with no work/school and thought I would practice.

You will need a C++ compiler and Windows to run it.


#include <iostream>
#include <string>
#include <windows.h>
#include <conio.h>
#include <iomanip>
using namespace std;

int main (){

string first="st";
string second="nd";
string third="rd";
string forth="th";
string append;
string of;
char ballsign='s';
int ballon;
string gol ="";
turnover:
reset:
int down=1;
int distance=10;
int gainloss=0;
int tdyards;
int i=0;
int ndown;
int ndistance;
char nballsign;
int nballon;
system("cls");
cout << "\n\n\n\n\n\n\n\n\n\nWhat yardline is the ball on?" <<endl;
cin >> ballsign;
if (ballsign =='r'){
goto reset;
}
cin >> ballon;
system("cls");
if (ballsign =='+' && ballon <= 10)
{
distance = ballon;
}
system("cls");
append = first;
//if turnover 1st and goal
goto output;

begin:

cin >> gol;
if (gol =="r"){
goto reset;
}
if (gol =="c"){
goto correction;
}
if (gol =="to"){
goto turnover;
}

if (gol =="td"){
touchdown:
system("cls");
if (ballsign =='-'){
tdyards = 100 - ballon;
}
else {
tdyards = ballon;
}
ballsign ='+';
ballon =3;
cout << fixed
<< setw(37) <<"Previous Play: "<<"Touchdown of " <<tdyards <<" yards" <<endl
<<" " <<"------------------------------------" <<endl
<<" "
<< setw(5)<< "Down"
<< setw(10)<< "Distance"
<< setw(12)<< "Ball On"
<<endl;


cout <<" "
<< setw(9)<< "PAT"
<< setw(8)<< "PAT"
<< setw(10)<< ballsign << ballon
<<endl
<<" " <<"------------------------------------" <<endl
<<endl;
cin.get();
cin.get();
system("cls");
goto turnover;
}
if (gol == "b"){
goto newballon;
}
//if (gol != "b" || "td" || "gain" || "loss" || "r" || "c" || "to"){
//system("cls");
//cout << "Invalid input, press any key to reset the program..." <<endl;
//cin.get();
//cin.get();
//goto reset;
//}
cin >> of;
cin >> gainloss;
//cout << of << gainloss <<endl;
//system("pause");
system("cls");
//if gain
if (gol == "gain")
{
if (gainloss < distance)
{ down ++;
if (ballsign =='+')
{
ballon=ballon-gainloss;
distance = distance - gainloss;
if(ballon < 1){
goto touchdown;
goto turnover;
}
}
//if ballsign is -
else {
ballon=ballon + gainloss;
distance = distance - gainloss;

if (ballon > 50){
ballsign='+';
ballon=100-ballon;

}
}

}
//gainloss > distance
else {
down=1;
distance =10;
if (ballsign =='-'){
ballon=gainloss + ballon;
}
else {
ballon = ballon - gainloss;
if(ballon < 1){
goto touchdown;
goto turnover;
}
}
if (ballon > 50)
{
ballsign ='+';
ballon = ballon-50;
ballon = 50-ballon;
if(ballon < 1){
goto touchdown;
goto turnover;
}
}
//cout << "ballon is "<< ballon << endl;

//goal to go
if (ballsign =='+' && ballon <= 9)
{

distance = ballon;
if(ballon < 1){
goto touchdown;
goto turnover;
}
}
}
}
//if loss
if (gol == "loss")
{
down ++;
distance = distance + gainloss;
if(ballsign =='+')
{
ballon = ballon+gainloss;
if (ballon > 50)
{
ballsign ='-';
ballon = 100-ballon;
}
}
else
{
ballon = ballon - gainloss;
}

}
correction:
while (gol == "c" && i < 1)
{system("cls");
cout << "****CORRECTION****" <<endl;
cout << "enter down" <<endl;
cin >> ndown;
cout << "enter distance" <<endl;
cin >> ndistance;
cout << "enter ball on" <<endl;
cin >> nballsign;
cin >> nballon;
system("cls");
if (ndown ==0){
down =down;
}
else {down = ndown;}
if (ndistance ==0){
distance = distance;
}
else {distance = ndistance;}
if (nballsign==0 || nballon ==0){
ballsign = ballsign;
ballon = ballon;
}
else {ballon=nballon; ballsign = nballsign;}
i++;

newballon:
if (gol == "b")
{system("cls");
cout << "New Ballspot?" <<endl;
cin >> nballsign >> nballon;
if (nballsign =='+' && ballsign=='-'){
gol = "gain";
of = "of";
gainloss = (100 - (ballon + nballon));
}
if (nballsign =='-' && ballsign=='+'){
gol = "loss";
of = "of";
gainloss = (100 - (ballon + nballon));
}
if (nballsign =='+' && ballsign=='+' && nballon < ballon){
gol = "gain";
of = "of";
gainloss = (ballon - nballon);
}
if (nballsign =='+' && ballsign=='+' && nballon > ballon){
gol = "loss";
of = "of";
gainloss = (nballon - ballon);
}
if (nballsign =='-' && ballsign=='-' && nballon > ballon){
gol = "gain";
of = "of";
gainloss = (nballon - ballon);
}
if (nballsign =='-' && ballsign=='-' && nballon < ballon){
gol = "loss";
of = "of";
gainloss = (ballon - nballon);
}
ballsign= nballsign;
ballon = nballon;
if (gol =="gain" && gainloss < distance)
{down ++;
distance = distance -gainloss;
}
if (gol =="gain" && gainloss > distance && (ballsign !='+' && ballon <= 10))
{down =1;
distance =10;
}
if (gol =="gain" && gainloss > distance && (ballsign =='+' && ballon <= 10) && distance != ballon)
{down =1;
distance =ballon;
}
if (gol =="loss")
{down ++;
distance = distance + gainloss;
}
}

}
if (down ==1)
{append = first;
}
if (down ==2)
{append = second;
}
if (down ==3)
{append = third;
}
if (down ==4)
{append = forth;
}
if (gol =="c")
{gol ="";
gainloss=0;
}
output:
system("cls");
if (ballsign =='+' && ballon==distance)
{
//if (gol != "gain" || "loss")
//{
// gol = " ";
// of = " ";
// gainloss = 0;
//}
cout << fixed
<< setw(40) <<" Previous Play: "<<gol <<" " << of << " "<<gainloss <<" yards" <<endl
<<" "
<<"------------------------------------" <<endl
<<" "
<< setw(5)<< "Down"
<< setw(10)<< "Distance"
<< setw(12)<< "Ball On"
<<endl;


cout <<" "
<< setw(7)<< down <<append
<< setw(8)<< "Goal"
<< setw(10)<< ballsign << ballon
<<endl
<<" "
<<"------------------------------------" <<endl
<<endl;
}
else
{
cout << fixed
<< setw(40) <<" Previous Play: "<<gol <<" " << of << " "<<gainloss <<" yards" <<endl
<<" "
<<"------------------------------------" <<endl
<<" "
<< setw(5)<< "Down"
<< setw(10)<< "Distance"
<< setw(12)<< "Ball On"
<<endl;


cout <<" "
<< setw(7)<< down <<append
<< setw(8)<< distance
<< setw(10)<< ballsign << ballon
<<endl
<<" "
<<"------------------------------------" <<endl
<<endl;
}
cout << "\n\n\n\n\n\n\n\n\n\nWhat happened on the previous play? \nPress 'r' to Reset Program\nPress 'c' for Corrections\nPress 'b' for new ballspot" <<endl;
//cout << ballsign <<endl;
while (down <=4){

goto begin;

}
system("pause");

}

cleller
12/23/2011, 08:50 AM
OK you win today's brainiac door prize.

I take it C++ is a computer language. Is it more advanced than FORTRAN?

Pricetag
12/23/2011, 11:47 AM
In my programming class my senior year in high school, I wrote a BASIC text-based program where you're the Houston Oilers, taking over at your 20 for one final chance to score a touchdown against the Philadelphia Eagles. You chose your play among a run, a short pass, or a long pass, and then it used a random number generator to decide the result of the play. If you scored on the long pass, the play by play that appeared on the screen was the same as Keith Jackson's TD against Penn State in the Orange Bowl in 1986. "Home run ball. . .DREW HILL HAS IT!"

Petro-Sooner
12/23/2011, 12:30 PM
OK you win today's brainiac door prize.

I take it C++ is a computer language. Is it more advanced than FORTRAN?

I was about ti ask the same thing. Only program class I ever had.

oudavid1
12/23/2011, 03:52 PM
FORTRAN is an old-school language with a lot of the same concepts but it is not nearly as easy. C++ is a more modern one. I keep adding to this code if anyone is interested. I know I am not the biggest nerd on this website.

jkjsooner
12/29/2011, 01:17 PM
Man, last time I programmed in C++ there was no such thing as a string type. It was either char pointers, a user defined class, or from third party libraries.

By the way, get out of the habit of using the goto statement.

Pricetag
12/29/2011, 06:23 PM
By the way, get out of the habit of using the goto statement.
That was strictly forbidden when I was in school 12 years ago. "Goto-less" was a term I heard over and over.

StoopTroup
12/29/2011, 08:57 PM
So much easier than punch cards....lol Running a batch was so much fun.

http://www.computersciencelab.com/ComputerHistory/HtmlHelp/Images2/Keypunch.jpg

5thYearSooner
12/30/2011, 11:48 AM
Dude, that looks like a C program... I didn't run it yet but if you could, use OOPS ..much better than C..also make function calls instead of goto..."goto is a big nono"

mdklatt
12/31/2011, 11:56 AM
Dude, that looks like a C program... I didn't run it yet but if you could, use OOPS ..much better than C..also make function calls instead of goto..."goto is a big nono"

THIS. ^^^

My personal preference is to initialize variables like "int i(0)" instead of like "int i = 0". The former is the constructor syntax, which works for built-in types as well as objects so I think it's more consistent. There are a couple of exceptions where you can't use the constructor syntax, though. Use const early and often. I'm doing a lot of Python right now, and the lack of const has bitten me in the *** more than once. When you're starting out, make every every variable const unless it gives you a compile error. Even then, make sure you understand the error and whether or not the variable really should be const.

mdklatt
12/31/2011, 12:08 PM
FORTRAN is an old-school language with a lot of the same concepts but it is not nearly as easy. C++ is a more modern one. I keep adding to this code if anyone is interested. I know I am not the biggest nerd on this website.

Fortran 2008 has many of the same features as C++ (but good luck finding a conforming compiler), although they're bolted-on rather clumsily because backwards compatibility is paramount with Fortran and it's been around a long time. Fortran is still the preferred way to code stuff that is heavily numeric, and it still dominates sciences.