Requirements
VULTURE IS V, OWL IS O, EAGLE IS E...
A for loop to input the data each bird watcher has collected.
inside the for loop, a do ... while loop to input and process the data collected by one bird watcher.
inside the do ... while loop a switch statement is used to calculate the number of eggs for each type of bird. the default option, which does nothing, is used when an x is entered.
the do ... while loop is exited when an X is entered for the type of bird.
The totals part is fine as per code below
ok, now my problem is I can't seem to get through my switch case. It prompts me for the first watcher's info, when I enter it, it never moves over to the next watcher.
The input data given is
3
E2 O1 V2 E1 O3 X0
V2 V1 O1 E3 O2 E1 X0
V2 E1 X
And here is the code that I got so far:
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int totNrVultureEggs, totNrEagleEggs, totNrOwlEggs, nrEggs,
nrVultureEggs, nrEagleEggs, nrOwlEggs, nrBirdWatchers, nrEggsEntered;
char bird;
// initialize grand totals for number of eggs for each type of bird
cout << "How many bird watchers took part in the study?";
cin >> nrBirdWatchers;
// loop over number of bird watchers
for (int i = 0; i < nrBirdWatchers ;i++ )
{
// initialize totals for number of eggs for each type of bird
// this bird watcher saw
nrVultureEggs = 0;
nrEagleEggs = 0;
nrOwlEggs = 0;
cout << "\nEnter data for bird watcher " << i + 1 << ":" << endl;
//loop over bird watchers
do{
cin >> bird >> nrEggs;
switch (bird)
{
case 'E':
case 'e':
nrEagleEggs = nrEagleEggs + nrEggs;
case 'O':
case 'o':
nrOwlEggs = nrOwlEggs + nrEggs;
case 'V':
case 'v':
nrVultureEggs = nrVultureEggs + nrEggs;
default :
nrBirdWatchers++;
break;
}
}while (i < nrBirdWatchers )
;
cout << "Bird watcher " << i + 1 << " saw " << nrVultureEggs;
cout << " vulture eggs, " << nrEagleEggs << " eagle eggs and ";
cout << nrOwlEggs << " owl eggs " << endl;
// increment grand totals for eggs
}
// display results
cout << "\nTotal number of vulture eggs: " << totNrVultureEggs;
cout << "\nTotal number of eagle eggs: " << totNrEagleEggs;
cout << "\nTotal number of owl eggs: " << totNrOwlEggs;
return 0;
}
You need a break after each switch case. Also, you need a boolean variable 'done' to tell you when a single birdwatcher is done.
bool done = false; //Flag to note when a birdwatcher is done
do {
string data;
cin >> data;
bird = data[0];
nrEggs = data[1]-0;
switch (bird)
{
case 'E':
case 'e':
nrEagleEggs = nrEagleEggs + nrEggs;
break; //was missing before
case 'O':
case 'o':
nrOwlEggs = nrOwlEggs + nrEggs;
break; //was missing before
case 'V':
case 'v':
nrVultureEggs = nrVultureEggs + nrEggs;
break; //was missing before
default :
done = true; //changed: No more birds to report
break;
}
}while (!done) //Check if there are birds to report
I rewrote the whole program, now it works, but take care of the input:
because of the type of the input, you have to give ALWAYS a couple of char-int, or you will have a bad time xD [The problem is in the buffer].
So the input would be:
3
E2 O1 V2 E1 O3 X0
V2 V1 O1 E3 O2 E1 X0
V2 E1 X0
The source below:
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
bool done;
char birdType;
int eagleEggs, owlEggs, vultureEggs;
int totEagleEggs, totOwlEggs, totVultureEggs;
int eggsTemp, eggsIn, birdWatchers;
cout << "How many bird watchers took part in the study?";
cin >> birdWatchers;
totEagleEggs = totOwlEggs = totVultureEggs = 0;
for (int i = 0; i < birdWatchers ;i++ ){
eagleEggs = owlEggs = vultureEggs = 0;
done = false;
cout << endl;
cout << "Enter data for bird-watcher n. " << (i + 1) << ":" << endl;
do{
cin >> birdType >> eggsTemp;
switch (birdType)
{
case 'E':
case 'e':
eagleEggs += eggsTemp;
totEagleEggs += eagleEggs;
break;
case 'O':
case 'o':
owlEggs += eggsTemp;
totOwlEggs += owlEggs;
break;
case 'V':
case 'v':
vultureEggs += eggsTemp;
totVultureEggs += vultureEggs;
break;
default:
done = true;
}
}while (!done);
cout << "The bird-watcher n. " << (i + 1) << " saw " << vultureEggs;
cout << " vulture eggs, " << eagleEggs << " eagle eggs and ";
cout << owlEggs << " owl eggs." << endl;
}
cout << endl;
cout << "Total number of vulture eggs: " << totVultureEggs << endl;
cout << "Total number of eagle eggs: " << totEagleEggs << endl;
cout << "Total number of owl eggs: " << totOwlEggs << endl;
system("PAUSE");
return 0;
}
Related
This program is essentially supposed to count the results of random throws of a dice 100 times and count the occurrence of each face then display all of them as a histogram of asterisks. It would seem the functions could be working but i'm unable to verify because after I make my choice, nothing displays.
#include <iostream>
#include <iomanip>
#include <string>
#include <random>
#include <sstream>
using namespace std;
enum class Side {
ONE, TWO, THREE, FOUR, FIVE, SIX
};
struct Bar {
int value;
Side label;
};
//roll dice function
void rollDice( Bar h[], int n = 100);
void rollDice( Bar h[], int){
default_random_engine en;
uniform_int_distribution<> dist{1,6};
int results[] ={0,0};
for( int n; n<=100; n++){
cout << dist(en);
results[dist(en)]++;
h[n].value = results[n];
if(h[n].value == 1){
h[n].label = Side::ONE;
}
else if(h[n].value == 2){
h[n].label = Side::TWO;
}
else if(h[n].value == 3){
h[n].label = Side::THREE;
}
else if(h[n].value == 4){
h[n].label = Side::FOUR;
}
else if(h[n].value == 5){
h[n].label = Side::FIVE;
}
else {
h[n].label = Side::SIX;
}
}
};
string getHistogram(Bar h[], char c = '*');
string getHistogram(Bar h[], char c ){
stringstream ast;
for( int n; n<=100; n++){
switch (h[n].label)
{
case Side::ONE:
return to_string(c);
break;
case Side::TWO:
return to_string(c);
break;
case Side::THREE:
return to_string(c);
break;
case Side::FOUR:
return to_string(c);
break;
case Side::FIVE:
return to_string(c);
break;
case Side::SIX:
return to_string(c);
break;
default:
break;
}
}
ast << "One: " << c << endl;
ast << "Two: " << c << endl;
ast << "Three: " << c << endl;
ast << "Four: " << c << endl;
ast << "Five: " << c << endl;
ast << "Six: " << c << endl;
string output = ast.str();
cout<< output;
return output;
}
int main (){
Bar histogram[] = {
{0,Side::ONE},{0,Side::TWO}, {0,Side::THREE},
{0,Side::FOUR},{0,Side::FIVE}, {0,Side::SIX}
};
char choice;
do {
cout << "DICE ROLLING SIMULATION" << endl
<<"===============================" << endl
<< "r. Roll Dice" << endl
<< "h. Display histogram" << endl
<< "q. Quit program\n" << endl
<< "\nEnter your choice:" << endl;
// Reading a single character using the scanner
cin >> choice;
switch(choice) {
case 'r': case 'R':
rollDice(histogram, 100);
break;
case 'h': case 'H':
cout<< getHistogram(histogram, '*');
break;
case 'q': case 'Q':
cout << "Good bye\n" << endl;
break;
default:
cout << "Invalid choice\n" << endl;
}
} while(choice != 'q');
}
So, this code contains many different mistakes. Let's go in order.
In structBar label may be const
struct Bar {
int value;
const Side label;
};
You don't need forward declaration for function signature
In rollDice you have many unnecessary local variables and I would use mt19937 random generator. So rollDice will look like this
void rollDice(Bar h[], int count = 100) {
default_random_engine en;
uniform_int_distribution<> dist{1,6};
for( int n = 0; n <= count; n++) {
cout << dist(en) << endl;
const auto index = dist(en) - 1;
++h[index].value;
}
};
In getHistogram you have return to_string(c); in switch therefore you don't see histogram. You can delete swith because you can match index and Side. And why cycle up to 100?
string getHistogram(Bar h[], char c = '*') {
stringstream ast;
for( int n = 0; n <= 5; n++) {
const string strValue = string(h[n].value, c);
switch (h[n].label)
{
case Side::ONE: ast << "One: "; break;
case Side::TWO: ast << "Two: "; break;
case Side::THREE: ast << "Three: "; break;
case Side::FOUR: ast << "Four: "; break;
case Side::FIVE: ast << "Five: "; break;
case Side::SIX: ast << "Six: "; break;
}
ast << strValue << '(' << h[n].value << ')' << endl;
}
return ast.str();
}
In main function you have to clear histogram before next rollDice
case 'r': case 'R':
for (Bar& b : histogram) {
b.value = 0;
}
rollDice(histogram, 100);
break;
Full version
#include <iostream>
#include <iomanip>
#include <string>
#include <random>
#include <sstream>
using namespace std;
enum class Side {
ONE, TWO, THREE, FOUR, FIVE, SIX
};
struct Bar {
int value;
Side label;
};
void rollDice(Bar h[], int count = 100) {
default_random_engine en;
uniform_int_distribution<> dist{1,6};
for( int n = 0; n <= count; n++) {
cout << dist(en) << endl;
const auto index = dist(en) - 1;
++h[index].value;
}
};
string getHistogram(Bar h[], char c = '*') {
stringstream ast;
for( int n = 0; n <= 5; n++) {
const string strValue = string(h[n].value, c);
switch (h[n].label)
{
case Side::ONE: ast << "One: "; break;
case Side::TWO: ast << "Two: "; break;
case Side::THREE: ast << "Three: "; break;
case Side::FOUR: ast << "Four: "; break;
case Side::FIVE: ast << "Five: "; break;
case Side::SIX: ast << "Six: "; break;
}
ast << strValue << '(' << h[n].value << ')' << endl;
}
return ast.str();
}
int main (){
Bar histogram[] = {
{0, Side::ONE},
{0, Side::TWO},
{0, Side::THREE},
{0, Side::FOUR},
{0, Side::FIVE},
{0, Side::SIX}
};
char choice;
do {
cout << "DICE ROLLING SIMULATION" << endl
<<"===============================" << endl
<< "r. Roll Dice" << endl
<< "h. Display histogram" << endl
<< "q. Quit program\n" << endl
<< "\nEnter your choice:" << endl;
// Reading a single character using the scanner
cin >> choice;
switch(choice) {
case 'r': case 'R':
for (Bar& b : histogram) {
b.value = 0;
}
rollDice(histogram, 100);
break;
case 'h': case 'H':
cout << getHistogram(histogram, '*') << endl;
break;
case 'q': case 'Q':
cout << "Good bye\n" << endl;
break;
default:
cout << "Invalid choice\n" << endl;
}
} while(choice != 'q');
}
I am trying to calculate the average for a class from scores given using a data file that was given.
The formula I'm using is grade_Average = sum / i;
The data file that was given is :
Joe Johnson 89
Susie Caldwell 67
Matt Baker 100
Alex Anderson 87
Perry Dixon 55
The output I am getting is
Johnson,Joe B
Caldwell,Susie D
Baker,Matt A
Anderson,Alex B
Dixon,Perry F
Class average inf
I am not sure if I have the formula wrong or if the formula is in the wrong place.
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
// Variable declarations:
string fName[10];
string lName[10];
float grade_Average;
string file;
string name;
int scores[10];
float sum = 0;
char grade;
int i = 0;
ifstream din;
// Function body:
cout << "Enter the name of the file. " << endl;
cin >> file;
din.open(file.c_str());
if (!din)
{
cout << " Cannot open the input file. Please try again." << endl;
return 0;
}
cout << setw(10) << setfill(' ') << "Name" <<setw(20)<<setfill(' ')<< "Grade" << endl;
while (!din.eof())
{
din >> fName[i];
din >> lName[i];
din >> scores[i];
sum = sum + scores[i];
switch (static_cast<int> (scores[i]/10))
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
grade = 'F';
break;
case 6:
grade = 'D';
break;
case 7:
grade = 'C';
break;
case 8:
grade = 'B';
break;
case 9:
grade = 'A';
break;
case 10:
grade = 'A';
break;
default:
cout << "Invalid score." << endl;
i++;
}
name = lName[i] + ',' + fName[i];
cout << setw(10) << setfill(' ') << name << setw(20) << setfill(' ')<<(" ") << grade << endl;
}
grade_Average = sum / i;
cout << "Class average " << grade_Average << endl;
din.close();
return 0;
}
Your i++ is inside the default block. The i variable is most probably 0. Either you put i++ outside of the switch block or you put it before every break statement.
i++ is inside the switch block and in the default case. It will never be executed for the given input. Therefore throughout the run i will just be 0. Dividing by 0 gives you inf.
Your program will also fail if more than 10 entries are given (and the first issue is corrected). You should use std::vector<std::string>, std::vector<int> and push_back instead of the raw arrays of std::string and int, if these arrays are needed at all. (For just calculating the average, the individual entries don't really need to be saved.)
This code is working fine, however this whole time I've tried avoiding using the goto statements that you will see in the switch (dice_total) statement.
Without the goto statements, the program will not loop back to the beginning of while (again=='y' || again=='Y'), and instead it keeps looping itself when it reaches the do-while loop.
However, I believe that it is also important to say, that if dice_total is = to the point_total the first time around then the program will function properly, and loop back to the beginning. For example, when the program starts, the first round will generate the point_total, which we will say its 10. Which is a value that will allow the program to continue to the next round, and if the dice_total also gets the same number, 10, the program will say you win, and the loop will work properly. However, if the program reaches the do while loop, and generates a number that isn't 10, but generates a 10 after a few loops, then the program will not loop to the beginning. So what I want to ask, what is wrong with my switch(dice_total) statement, and how can I fix it, to give the program the same effect without using the goto statements?
#include "stdafx.h"
#include <iostream>
#include <random>
#include <string>
using namespace std;
int main()
{
//Declared Variables***********************************
char again = 'y';
int point1;
int point2;
int point_total;
int round_1=1;
int dice1;
int dice2;
int dice_total;
//*****************************************************
//RANDOM SEED******************************************
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int>dist(1, 6);
//*****************************************************
start://TEMPORARY
while (again == 'y'||again=='Y')
{
int round_1 = 1;
system("CLS");
cout << "WELCOME TO THE CRAPS GAME" << endl;
cout << "THROWING ROUND:" << round_1 << " DICES.............." << endl;
point1 = dist(mt);
point2 = dist(mt);
point_total = point1 + point2;
cout << "ROUND: " << round_1 << " First dice is: " << point1 << " and second dice is: " << point2 <<" and the total is:"<<point_total<< endl;
switch (point_total)
{
case 7:
case 11:
cout << "YOU WON CONGRATS PRESS Y TO PLAY AGAIN!!" << endl;
cin >> again;
break;
case 2:
case 3:
case 12:
cout << "YOU LOST, PRESS Y TO TRY AGAIN" << endl;
cin >> again;
break;
default:
do
{
++round_1;
cout << "ROUND " << round_1 << endl;
dice1 = dist(mt);
dice2 = dist(mt);
dice_total = dice1 + dice2;
cout << "THROWING ROUND: " << round_1 << " DICES.............." << endl;
cout << "ROUND 1 DICE TOTAL IS: " << point_total << endl;
cout << "ROUND: " << round_1 << " First dice is: " << dice1 << " and second dice is: " << dice2 << " and the total is:" << dice_total << endl;
switch (dice_total)
{
case 11:
cout << "YOU WON CONGRATS PRESS Y TO PLAY AGAIN!!" << endl;
cin >> again;
goto start;
case 2:
case 3:
case 7:
case 12:
cout << "YOU LOST, PRESS Y TO TRY AGAIN" << endl;
cin >> again;
goto start;
default:
if (dice_total == point_total)
{
cout << "YOU WON CONGRATS PRESS Y TO PLAY AGAIN!!<<endl;
cin >> again;
break;
}//if
else
{
cout << "Going to next round" << endl;
}
}//dice_total
}//do
while (dice_total != point_total);
break;
}//switch point
}//again while
}//main
The problem you're facing is usual when you have too many nested loops in the same function, and is an indicator that you need to refactor parts of your code to be in their own functions.
If you do this, then you have more possibilities to control the flow of your code: in each function you have break and return, and as you can return a custom value, you can use it to determine in the surrounding function if you need to break or return again.
Besides, this gives you the opportunity to put self-explanatory names to your functions, which makes your code clearer for people that look at it for the first time (as it's written, it's so dense that I can't understand it unless I stare at it for some minutes).
An example of what I mean in code:
Before
int main() {
start:
while (a) {
b1();
switch(c) {
case 1:
do {
d();
if (cond) goto start;
} while(e);
break;
}
b2();
}
}
After
int main() {
while (a) {
if (!doStuff1())
break;
}
...
}
bool doStuff1() {
b1();
while (a) {
bool res = doStuff2();
if (res) return true;
}
b2();
...
}
bool doStuff2() {
switch(c) {
case 1:
if (doStuff3()) return true;
}
return false;
}
bool doStuff3() {
do {
d();
if (cond) return true;
} while (e);
return false;
}
How about this design?
bool stop=false;
while(!stop && (again == 'y'||again=='Y'))
{
while(again == 'y'||again=='Y')
{
// ...
break; /* breaks inner while*/
// ...
stop=true;
break; /* breaks inner while, and prevents running outer loop*/
}
}
Please help! I can't produce the output of my program. This is the condition:
Construct a program that gives a discount of 100 pesos if the shirt bought is XL and the the price is greater than 500; and a discount of 50 pesos if the shirt bought is L and the price is greater than 600.
#include <iostream>
using namespace std;
int main()
{
int p;
int s;
cout << "Input price: ";
cin >> p;
cout << "Input size: ";
cin >> s;
switch (s)
{
case 'XL': case 'xl':
{
if (p>500){
cout << "Total price: " << p-100 << " pesos.";
break;
}
else if ((s=='XL' || s=='xl') && (p<500)){
cout << "Total price: " << p << " pesos.";
break;
}
}
case 'L': case 'l':
{
if (p>600){
cout << "Total price: " << p-50 << " pesos.";
break;
}
else if ((s=='XL' || s=='xl') && (p<600)){
cout << "Total price: " << p << " pesos.";
break;
}
}
case 'M': case 'm':
{
cout << "Total price: " << p << " pesos.";
break;
}
case 'S': case 's':
{
cout << "Total price: " << p << " pesos.";
break;
}
}
return 0;
}
The output of the program:
Input price: 500
Input size: XL
Process returned 0 (0x0) execution time : 5.750 s
Press any key to continue.
P.S. How can I remove the warning (multi-character character constant) in my program?
Thanks in advance!
If the size can be more than a single character, then you'll need to represent it with a string. You can't switch on a string, so you'll have to use if..else..else.. to deal with the value:
std::string size;
cin >> size;
if (size == "XL") {
// deal with size XL
} else if (size == "L") {
// deal with size L
} // and so on
If it were a single character, then you could use char (not int) to represent that:
char size;
cin >> size;
switch (size) {
case 'L':
// deal with size L
break;
// and so on
}
but for multiple characters, you'll need a string.
switch statement can handle int and char in C++. char data type can hold only one letter. Thus, if you input only one letter (X) for XL size will be fine ...
cout << "Input size (X/L/M/S): ";
cin >> s;
switch (s){
case 'X': case 'x':
You've declared s as an integer but attempt to use it as a character and character array. You should probably declare it is char s; and then use it consistently as just a single character -- which does mean that you can't check for XL. You could, however, just check for X in your switch.
If you absolutely must check for XL, then you'll need to use either a character array or std::string, although switch statements can only be used with single characters, so you may have to nest your switch to check for multiple characters or just use a series of if (strncmp(...)...) calls.
I want to remove using namespace std, but I don't know what all needs to be prefixed.
#include <iostream>
#include "PlayingCard.h"
using namespace std;
PlayingCard makeValidCard(int value, int suit);
int main()
{
// Create a playing card
PlayingCard card1;
// Test the default constructor and GetCardCode
cout << "Testing default constructor. Expect card code to be 00\n card code is :";
cout << card1.getCardCode() << endl << endl;
// Test the setter and getter
cout << "Seting card to 'AH' using SetValue and SetSuit" << endl;
card1.setCard('A', 'H');
cout << "GetValue returns :" << card1.getValue() << endl;
cout << "GetSuit returns :" << card1.getSuit() << endl << endl;
// Test overloaded constructor
PlayingCard tenOfSpades('T', 'S');
cout << "Testing overloaded constructor. Expect card code to be TS\n card code is :";
cout << tenOfSpades.getCardCode() << endl << endl;
// Test IsValid with valid cards
cout << "Testing valid card codes.\n"
<< "Expect isValid to return true for all (except perhaps Jokers.)"
<< endl;
// Create and test valid cards
int validCards = 0; // cards that return true for IsValid
int invalidCards = 0; // cards that return false for IsValid
// Create and test four suits plus the jokers
for(int suit = 1; suit <= 5; suit++)
{
// Create and test ace, 2 - 9, Jack, Queen, and King
for(int value = 1; value <= 13; value++)
{
PlayingCard aCard = makeValidCard(value, suit);
cout << "Card Code: " << aCard.getCardCode() << " IsValid :";
if (aCard.isValid())
{
validCards++;
cout << "true" << endl;
}
else
{
invalidCards++;
cout << "false" << endl;
}
// suit 5 is just for creating the two Jokers
if (suit == 5 && value >= 2)
break;
}
}
cout << "IsValid returned false for " << invalidCards << " card codes" << endl;
cout << "IsValid returned true for " << validCards << " card codes" << endl;
cout << endl;
// Test IsValid with invalid cards
// Create and test invalid cards
cout << "Testing invalid card codes; isValid should return false for all." << endl;
validCards = 0;
invalidCards = 0;
// Loop through all possible ASCII character codes for card codes
for(int suit = 0; suit <= 255; suit++)
for(int value = 0; value <= 255; value++)
{
// Only check card codes that are not valid
PlayingCard aCard = makeValidCard(value, suit);
if (aCard.getCardCode() == "00")
{
if (aCard.isValid())
{
cout << "value :" << value << " suit :" <<suit << " IsValid :";
cout << "true" << endl;
validCards++;
}
else
{
invalidCards++;
}
}
}
cout << "IsValid returned false for " << invalidCards << " card codes" << endl;
cout << "IsValid returned true for " << validCards << " card codes" << endl;
return 0;
}
/******************************************************/
/* Test Functions */
/******************************************************/
PlayingCard makeValidCard(int iValue, int iSuit)
{
char value = '0';
char suit = '0';
switch (iValue)
{
case 1:
value = 'A';
break;
case 10:
value = 'T';
break;
case 11:
value = 'J';
break;
case 12:
value = 'Q';
break;
case 13:
value = 'K';
break;
default:
if ((iValue >= 2) && (iValue <= 9))
value = '0' + iValue;
break;
}
switch (iSuit)
{
case 1:
suit = 'D';
break;
case 2:
suit = 'S';
break;
case 3:
suit = 'C';
break;
case 4:
suit = 'H';
break;
// Special case for the Joker
case 5:
if(iValue == 1)
{
value = 'Z';
suit = 'B';
}
else if(iValue == 2)
{
value = 'Z';
suit = 'R';
}
else
{
value = '0';
suit = '0';
}
break;
}
PlayingCard testCard(value, suit);
return testCard;
}
Just remove it and then prefix everything that the compiler errors on. :P
With a quick glance, what definitely needs to be prefixed are cout and endl.
Also, please do not use endl to just insert newlines, use plain old '\n' instead. endl not only inserts a newline, but also flushs the stream, which can be quite the performance penalty if used frequently (which you do). Only use it if you need the stream flushed in addition to inserting a newline.
I didn't look over the code with a fine tooth comb, but probably just cout and endl. If the compiler gives you an error about an undefined symbol, try adding std to that too. Incidentally, you could also change using namespace std; to using std::cout; and using std::endl; That would keep the global namespace from being overly polluted, but avoid adding the qualifier to every instance in your code.
The only two I see are cout and endl everything else is a keyword or user defined.
Given the frequency that you use cout, you might want to replace using namespace std; with using std::cout;.
As Xeo says, you should search-and-replace endl with '\n'.
It looks like that might cover all your bases. Fix any other compiler errors by adding std:: as they appear.