I cleaned up some code up to make it easier for me to post it here, but I came up with a problem when I wanted to ask the user if he wanted to check Running Back number two's stats. I don't know what I did wrong(might just be a mistake that I just cant catch) but I have done many for loops but none like this. Dev C++ gave me some error messages.
Code:
#include <iostream>
using namespace std;
class RunningBack // Class RunningBack Defined
{
// Setting up "Rush"
public:
int GetRush() const { return itsRush; }
void SetRush(int rush) { itsRush = rush; }
int GetPass() const { return itsPass; }
void SetPass(int pass) { itsPass = pass; }
int GetTD() const { return itsTD; };
void SetTD(int TD) { itsTD = TD; }
int GetFumb() const { return itsFumb; }
void SetFumb(int fumb) { itsFumb = fumb; }
private:
int itsRush;
int itsPass;
int itsTD;
int itsFumb;
};
int main()
{
RunningBack Back1;
RunningBack Back2;
int rush;
int x;
int pass;
int TD;
int total;
int fumb;
cout<< "How many yards did back number one have? " << endl;
cin >> rush;
rush = rush / 20;
Back1.SetRush(rush);
cout << "Back number one rushed for " << Back1.GetRush() << " point(s) rushing today\n";
cout << "------------------------------------------------------------\n\n\n" << endl;
cout << "How many yards receiving did back number one have? " << endl;
cin >> pass;
pass = pass / 20;
Back1.SetPass(pass);
cout << "Back number one caught for " << Back1.GetPass() << " point(s) receiving today\n";
cout << "-------------------------------------------------------------\n\n\n" << endl;
cout << "How many touchdowns did back number one have? " << endl;
cin >> TD;
TD = TD * 6;
Back1.SetTD(TD);
cout << "Back number one scored " << Back1.GetTD() << " point(s) in touchdowns today\n";
cout << "-------------------------------------------------------------\n\n\n" << endl;
cout << "How many fumbles did back number one have? " << endl;
cin >> fumb;
fumb = fumb * 2;
Back1.SetFumb(fumb);
cout << "Back number lost " << Back1.GetFumb() << " point(s) on fumbles today\n";
cout << "-------------------------------------------------------------\n\n\n" << endl;
total = rush + pass + TD - fumb;
cout << "Total points for back number one is " << total << endl;
cout << "-------------------------------------------------------------\n\n\n" << endl;
cout << "Do you want to view back number two's points?\nTo continue press 1\n If not press any key to exit";
cin >> x;
for ( x == 1 ); //expected '(' before ';' token
{ // expected primary-expression before '{' token. //expected ')' before '{' token
cout<< "How many yards did back number two have? " << endl;
cin >> rush;
rush = rush / 20;
Back2.SetRush(rush);
cout << "Back number one rushed for " << Back2.GetRush() << " point(s) rushing today\n";
cout << "------------------------------------------------------------\n\n\n" << endl;
cout << "How many yards receiving did back number two have? " << endl;
cin >> pass;
pass = pass / 20;
Back2.SetPass(pass);
cout << "Back number two caught for " << Back2.GetPass() << " point(s) receiving today\n";
cout << "-------------------------------------------------------------\n\n\n" << endl;
cout << "How many touchdowns did back number two have? " << endl;
cin >> TD;
TD = TD * 6;
Back2.SetTD(TD);
cout << "Back number two scored " << Back2.GetTD() << " point(s) in touchdowns today\n";
cout << "-------------------------------------------------------------\n\n\n" << endl;
cout << "How many fumbles did back number two have? " << endl;
cin >> fumb;
fumb = fumb * 2;
Back2.SetFumb(fumb);
cout << "Back number two lost " << Back2.GetFumb() << " point(s) on fumbles today\n";
cout << "-------------------------------------------------------------\n\n\n" << endl;
total = rush + pass + TD - fumb;
cout << "Total points for back number two is " << total << endl;
cin >> x;
}
return 0;
}
I looked up inheritance and derivation and will change "total" to GetTotal when I understand it all. If you have any other easier ways to ask for the stats of running back number two rather than my crude way of doing it please tell.
Also this problem where I'm not sure if I should make Back1's total a pointer or how to add the back1 with back2's total.
Code:
#include <iostream>
using namespace std;
class RunningBack // Class RunningBack Defined
{
// Setting up "Rush"
public:
int GetRush() const { return itsRush; }
void SetRush(int rush) { itsRush = rush; }
int GetPass() const { return itsPass; }
void SetPass(int pass) { itsPass = pass; }
int GetTD() const { return itsTD; };
void SetTD(int TD) { itsTD = TD; }
int GetFumb() const { return itsFumb; }
void SetFumb(int fumb) { itsFumb = fumb; }
int GetTotal() const { return itsTotal; }
void SetTotal(int total) { itsTotal = total; }
private:
int itsRush;
int itsPass;
int itsTD;
int itsFumb;
int itsTotal;
};
int main()
{
RunningBack Back1;
RunningBack Back2;
int rush;
int x;
int pass;
int TD;
int total;
int fumb;
int totalPoints;
int * ptotal;
cout<< "How many yards did back number one have? " << endl;
cin >> rush;
rush = rush / 20;
Back1.SetRush(rush);
cout << "Back number one rushed for " << Back1.GetRush() << " point(s) rushing today\n";
cout << "------------------------------------------------------------\n\n\n" << endl;
cout << "How many yards receiving did back number one have? " << endl;
cin >> pass;
pass = pass / 20;
Back1.SetPass(pass);
cout << "Back number one caught for " << Back1.GetPass() << " point(s) receiving today\n";
cout << "-------------------------------------------------------------\n\n\n" << endl;
cout << "How many touchdowns did back number one have? " << endl;
cin >> TD;
TD = TD * 6;
Back1.SetTD(TD);
cout << "Back number one scored " << Back1.GetTD() << " point(s) in touchdowns today\n";
cout << "-------------------------------------------------------------\n\n\n" << endl;
cout << "How many fumbles did back number one have? " << endl;
cin >> fumb;
fumb = fumb * 2;
Back1.SetFumb(fumb);
cout << "Back number lost " << Back1.GetFumb() << " point(s) on fumbles today\n";
cout << "-------------------------------------------------------------\n\n\n" << endl;
total = rush + pass + TD - fumb;
Back1.SetTotal(total);
total = *ptotal;
cout << "Total points for back number one is " << Back1.GetTotal()<< endl;
cout << "-------------------------------------------------------------\n\n\n" << endl;
cout<< "How many yards did back number two have? " << endl;
cin >> rush;
rush = rush / 20;
Back2.SetRush(rush);
cout << "Back number one rushed for " << Back2.GetRush() << " point(s) rushing today\n";
cout << "------------------------------------------------------------\n\n\n" << endl;
cout << "How many yards receiving did back number two have? " << endl;
cin >> pass;
pass = pass / 20;
Back2.SetPass(pass);
cout << "Back number two caught for " << Back2.GetPass() << " point(s) receiving today\n";
cout << "-------------------------------------------------------------\n\n\n" << endl;
cout << "How many touchdowns did back number two have? " << endl;
cin >> TD;
TD = TD * 6;
Back2.SetTD(TD);
cout << "Back number two scored " << Back2.GetTD() << " point(s) in touchdowns today\n";
cout << "-------------------------------------------------------------\n\n\n" << endl;
cout << "How many fumbles did back number two have? " << endl;
cin >> fumb;
fumb = fumb * 2;
Back2.SetFumb(fumb);
cout << "Back number two lost " << Back2.GetFumb() << " point(s) on fumbles today\n";
cout << "-------------------------------------------------------------\n\n\n" << endl;
total = rush + pass + TD - fumb;
Back2.SetTotal(total);
cout << "Total points for back number two is " << Back2.GetTotal() << endl;
*ptotal + total = totalPoints; //non-lvalue in assignment
cout << "Total Points for both backs: " << totalPoints << endl;
return 0;
}