Ok, so I'm making this code and I keep trying to make 'checkBalance' a function but it's not coming out right. I have a massive amount of errors and 1 warning that I need help fixing.
Also I'm not quite sure how to make the buyStock function pull the currentPrice of a certain stock from a file so I can add it to the balance from another file and write the new current balance out to a new file. I know I'm doing something wrong but I'm not sure what.
I'll be up all night if anyone can help me.
Thanks in advance;
~A
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
#include <iostream>
#include <string>
#include <fstream>
int sellStock();
using namespace std;
class stock{
public:
stock();
stock(string symbol);
// The properties of the class, often known as the member variables
std::string nameOfStock;
double currentPrice;
double previousClosingPrice;
double share, balance, amount;
string symbol;
// The methods I want to be able to call on the class
// For the difference in value, I should not need to provide any input when I make the
// function call; the object should keep track of its own member variables.
double getChangePercent();
};
stock::stock()
{
};
stock::stock(string inputSymbol)
{
// Lots of code to fetch values etc.
ifstream in("stock.txt");
if (in.is_open())
{
while(symbol!=inputSymbol)
{
in >> symbol;
in >> previousClosingPrice;
in >>currentPrice;
}
}
else
{
cout << "Cannot open file" << endl;
}
};
double stock::getChangePercent()
{
cout << "You have called getChangePercent on the stock object " << endl;
return 0.0;
};
struct stockAndAmount{
string stockName;
int amountOfStock;
};
class account{
public:
stockAndAmount stock1;
stockAndAmount stock2;
stockAndAmount stock3;
};
account buyStock(account inputAccount);
int main()
{
ifstream in;
string userAccount;
stock userStock;
cout<< "Please enter your four digit account number.\n";
cin>> userAccount;
if (userAccount =="0000"){
in.open("./Account_0000.txt");
if (in.is_open()){
cout <<"Opened account"<<endl;
//test for file opening
}
}
else
if (userAccount=="1234"){
ifstream in("Account_1234.txt");
}
else{
cout<< "Bad choice " << endl;
}
// User has chosen their account.
account usersActualAccount;
usersActualAccount.stock1.stockName;
in>> usersActualAccount.stock1.stockName;
in>> usersActualAccount.stock1.amountOfStock;
in>> usersActualAccount.stock2.stockName;
in>> usersActualAccount.stock2.amountOfStock;
in>> usersActualAccount.stock3.stockName;
in>> usersActualAccount.stock3.amountOfStock;
// Have just given the user some choices. Need to fetch their choice
int choice;
choice=0;
// We can make it loop until the user chooses to exit later
// let's get it working once first
while (choice!=7){
cout<<"Main Menu\n";
cout<<"1: Buy\n";
cout<<"2: Sell\n";
cout<<"3: Check balance\n";
cout<<"4: Check closing price\n";
cout<<"5: Check current price\n";
cout<<"6: Check percent change\n";
cout<<"7: Exit\n";
cin >> choice;
switch (choice){
case 1:
//go to buy option
buyStock(usersActualAccount);
break;
case 2:
//go to sell option
cout << "You chose 2" << endl; // To help us see it works
break;
case 3:
//go to check balance option
checkBalance(usersActualAccount);
break;
case 4:
//go to check closing price option
cout << userStock.previousClosingPrice << endl; // To help us see it works
break;
case 5:
//go to check current price option
cout << userStock.currentPrice << endl; // To help us see it works
break;
case 6:
//go to check getchangePercent
cout << userStock.getChangePercent() << endl;
break;
case 7:
//Exit
cout << "You chose to Exit." << endl;
cout <<"Thank you for your business.\n";
break;
}
}
return 0;
}
account usersActualAccount;
account checkBalance(usersActualAccount); {
//brings in users account data from file
usersActualAccount.stock1.stockName;
in>> usersActualAccount.stock1.stockName;
in>> usersActualAccount.stock1.amountOfStock;
in>> usersActualAccount.stock2.stockName;
in>> usersActualAccount.stock2.amountOfStock;
in>> usersActualAccount.stock3.stockName;
in>> usersActualAccount.stock3.amountOfStock;
//shows user their balance
cout<< usersActualAccount.stock1.stockName<<endl;
cout<< usersActualAccount.stock1.amountOfStock<<endl;
cout<< usersActualAccount.stock2.stockName<<endl;
cout<< usersActualAccount.stock2.amountOfStock<<endl;
cout<< usersActualAccount.stock3.stockNamee<<endl;
cout<< usersActualAccount.stock3.amountOfStock<<endl;
}
in.open("stock.txt");
in >> symbol;
in >> previousClosingPrice;
in >>currentPrice;
int buyStock();
double numberOfStock;
account buyStock(account inputAccount){
string userInput;
stock userStock;
cout<< "Which stock would you like to buy AAPL, GOOG or INTC?\n";
userStock.symbol = userInput;
cin>> userInput;
if ((userInput =="AAPL") ||
(userInput =="aapl") ||
(userInput =="GOOG") ||
(userInput =="goog") ||
(userInput =="INTC") ||
(userInput =="intc")){
stock userStock(userInput);
userStock.symbol = userInput;
else{
cout<< "Bad choice " << endl;
break;
}
cout<<"How many shares would you like to buy?\n";
cin>> numberOfStock
balance=balance+(numberOfStock*currentPrice)
cout <<"Your new balance is "<< balance<< endl;
}
return inputAccount;
}
|
Line Location main.cpp:211: error: expected declaration before '}' token
Line Location main.cpp:210: error: expected unqualified-id before 'return'
Line Location main.cpp:209: warning: control reaches end of non-void function
Line Location main.cpp:206: error: expected `;' before 'balance'
Line Location main.cpp:202: error: break statement not within loop or switch
Line Location main.cpp:200: error: expected `}' before 'else'
Line Location main.cpp:180: error: expected constructor, destructor, or type conversion before '>>' token
Line Location main.cpp:179: error: expected constructor, destructor, or type conversion before '>>' token
Line Location main.cpp:178: error: expected constructor, destructor, or type conversion before '>>' token
Line Location main.cpp:177: error: expected constructor, destructor, or type conversion before '.' token
Line Location main.cpp:159: error: expected ',' or ';' before '{' token
Line Location main.cpp:134: error: 'checkBalance' was not declared in this scope