//Additional homework - p171 #1,5,10 //Problem #1 - create a rock paper scissors game /* #include using namespace std; int main(){ char player1, player2; bool playmore = true; //loop game until user decides to quit while(playmore){ cout << "Rock Paper Scissors\n\n"; //get each player's move cout << "Player 1, Enter your move (R/P/S)"; cin >> player1; cout << "Player 2, Enter your move (R/P/S)"; cin >> player2; //compare the players' moves switch(player1){ //compare player 1's move 'rock' to player 2's possible moves case 'r': case 'R': switch(player2){ case 'r': case 'R': cout << "Rock and rock tie. Nobody wins.\n"; break; case 'p': case 'P': cout << "Paper covers rock. Player 2 wins.\n"; break; case 's': case 'S': cout << "Rock crushes scissors. Player 1 wins.\n"; break; default: cout << "Player 2 didn't make a valid choice. Player 1 wins.\n"; break; } break; case 'p': case 'P': switch(player2){ case 'r': case 'R': cout << "Paper covers rock. Player 1 wins.\n"; break; case 'p': case 'P': cout << "Paper and paper tie. Nobody wins.\n"; break; case 's': case 'S': cout << "Scissors cut paper. Player 2 wins.\n"; break; default: cout << "Player 2 didn't make a valid choice. Player 1 wins.\n"; break; } break; case 's': case 'S': switch(player2){ case 'r': case 'R': cout << "Rock crushes scissors. Player 2 wins.\n"; break; case 'p': case 'P': cout << "Scissors cut paper. Player 1 wins.\n"; break; case 's': case 'S': cout << "Scissors and scissors tie. Nobody wins.\n"; break; default: cout << "Player 2 didn't make a valid choice. Player 1 wins.\n"; break; } default: switch(player2){ case 'r': case 'R': case 'p': case 'P': case 's': case 'S': cout << "Player 1 didn't make a valid choice. Player 2 wins.\n"; break; default: cout << "You both failed to enter a valid choice. Maybe you would be better off playing tic tac toe?\n"; break; } } //give player opportunity to end the whole program's looping cout << "Would you like to play again?(Y/N)"; cin >> player1; if((player1=='n')||(player1=='N')) playmore = false; } cout << "Press enter to continue..."; fflush(stdin); cin.get(); } */ //SAMPLE RUN //Rock Paper Scissors //Player 1, Enter your move (R/P/S)R //Player 2, Enter your move (R/P/S)S //Rock crushes scissors. Player 1 wins. //Would you like to play again?(Y/N)Y //Rock Paper Scissors //Player 1, Enter your move (R/P/S)r //Player 2, Enter your move (R/P/S)p //Paper covers rock. Player 2 wins. //Would you like to play again?(Y/N)y //Rock Paper Scissors //Player 1, Enter your move (R/P/S)p //Player 2, Enter your move (R/P/S)p //Paper and paper tie. Nobody wins. //Would you like to play again?(Y/N)n //Press enter to continue... //Problem 5 - Compute a long distance charge. Calls on sat and sun are 15 cents / minute, weekdays between 8a and 6p are are 40c/minute, nights are 25c/minute //input should be Mo Tu We Th Fr Sa Su and 24h notation //Based on the phone company's way of doing it, the whole call will be charged according to the starting time. /* #include using namespace std; int main(){ char d1; char d2; int hour; int length; double charge = 0.00; int numericalDay; //Get the input for day call was made, hour call was begun and amount of minutes call lasted cout << "Long distance charge calculator\n"; cout << "Enter the day your call will be made\n(Mo Tu We Th Fr Sa Su): "; cin >> d1 >> d2; cout << "Enter the hour in which your call was made. Use 24 hour notation.\n(0-23; 0 = 12:00 AM 23 = 11:00PM): "; cin >> hour; cout << "Enter the number of minutes your call lasted: "; cin >> length; numericalDay = d1*d2; //Strings aren't allowed in switch statements, and adding the numerical values of the characters comes out with wed and thurs identical, so i multiplied them. switch(numericalDay){ case 8547: case 9828: case 8787: case 8736: case 7980: switch(hour){ case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 18: case 19: case 20: case 21: case 22: case 23: charge = .25; break; case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: charge = .40; break; default: cout << "There is something wrong with your hour.\n"; break; } break; case 8051: case 9711: charge = .15; break; default: cout << "There is something wrong with your day.\n"; break; } cout << "The cost of your call is $" << charge * length << ".\n"; cout << "Press enter to continue..."; fflush(stdin); cin.get(); } */ //SAMPLE RUN //Long distance charge calculator //Enter the day your call will be made //(Mo Tu We Th Fr Sa Su): Fr //Enter the hour in which your call was made. Use 24 hour notation. //(0-23; 0 = 12:00 AM 23 = 11:00PM): 7 //Enter the number of minutes your call lasted: 15 //The cost of your call is $3.75. //Press enter to continue... //Problem 10 - Crud Growth /* The Fibonacci numbers Fn are defined as follows: F0=1, F1=1, and Fi+2 = Fi + Fi+1 for i=0,1,2... . In other words, each number if the sum of the previous two numbers. The first few Fibonacci numbers are 1,1,2,3,5,8. One place that these numbers occur is as certain population growth rates. If a population has no deaths, then the series shows the size of the population after each time period. It takes an organism two time periods to mature to reproducing age, and then the organism reproduces once every time period. The formula applies most straightforwardly to asexual reproduction at a rate of one offspring per time period. Assume that the green crud population grows at this rate and has a time period of 5 days. Hence, if a green crud population starts out as 10 pounds of crud, then in 5 days there is still 10 pounds of crud; in 10 days there is 20 pounds of crud; in 15 days 30 pounds, in 20 days 50 pounds, and so forth. Write a program that takes both the initial size of a green crud population in pounds and a number of days as input and outputs the number of pounds of green crud after that many days. Assume that the population size is the same for four days and then increases every fifth day. */ /* #include using namespace std; int main(){ int spotA = 0, spotB = 1, current, length, days; cout << "Enter the amount of days the green crud will grow: "; cin >> days; length = days / 5; cout << "Enter the initial amount of green crud: "; cin >> current; spotB = current; for(int counter = 0; counter < length; counter++){ cout << " " << current << " "; current = spotA + spotB; spotA = spotB; spotB = current; } cout << "\nIn " << days << " days you will have grown " << current << "lbs of green crud."; cout << "\nPress enter to continue..."; fflush(stdin); cin.get(); } //SAMPLE RUN //Enter the amount of days the green crud will grow: 20 //Enter the initial amount of green crud: 10 // 10 10 20 30 //In 20 days you will have grown 50lbs of green crud. //Press enter to continue... */