Question



3. You should test your program on other test cases (tdhat you make up) as well. Making up good test cases is a valuable programming skill, and is part of ensuring your code solution is correct. Problem A: Number game (20 points) Write a C++ program that will play the following game. Ask the user how many rounds you want to play and start at 10 points. Every turn you can add either 1 point (by choosing a or 2 points (by choosing b).After adding this you should do one of two things .If the end result is a Fibonacci number, add to the current points the sum of the next n Fibonacci numbers starting at the Fibonacci numbe equal to the point value, where·n, is the current round. If on the 3 round you had 8 poines, since 8 is a Fibonacci number you would compate the new score as: 8+ (8-13 21)-50 *If the end result is not a Fibonacci number, divide it by two and round down any fractions At the start of each round tell them how many points they cumently have and ask what they want to do. If it is the final round, tell them their final score and end the program. Example 1 (user input is underlined) How many rounds Current points: 10 Choose: (a) add 1 point, (b) add 2 points Current points: 5 Choose: (a) add 1 point, (b) add 2 points..- Current points: 3 Choose: (a) add 1 point, (b) add 2 points Final score Example 2 (user input is underlined) How many rounds7 Current points: 10 Choose: (a) add 1 point. (b) add 2 points Current points:6 Choose: (a) add 1 point. (b) add 2 points.. Current points: 29 Choose: (a) add1 point, (b) add 2 points... Current points: 15 Choose: (a) add 1 point, (b) add 2 points Current points: Choose: (a) add 1 point (b) add 2 points... Final score When you are done, name the source code file cusermame 3A.cpp. Here you replace Cusername> with your U of M email address; for example, if your email address is smithx 1234@umn.edu, your file should be named smildx 1234 3A pp. Then submit your program using the HW 3 Problem A submission link n Moodle
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Username_3A.cpp

#include<iostream>

using namespace std;

int main()

{

// variables declaration

char c;

int rounds,points=10;

cout<<"How many rounds?"<<endl;

cin>>rounds; // getting number of rounds from user

cout<<"Current points: "<<points<<endl;

// for loop executes round number of times

for(int i=1;i<=rounds;i++)

{

int f1=1,f2=1,f3=0;

cout<<"Choose: (a) add 1 point, (b) add 2 points..."<<endl;

cin>>c; // getting user choice a or b

if(c=='a') // if a add 1 point

points=points+1;

else

if(c=='b') // if b add 2 points

points=points+2;

// creating fibonacci series upto points

while(true)

{

f3=f1+f2;

f1=f2;

f2=f3;

if(f3>=points)

break;

}

// checking new points are in fibonacci series or not

if(f3==points)

{

// if yes then add next fibonacci number in points

// next fibonacci numbers of round number times

for(int j=1;j<=i;j++)

{

points=points+f3;

f3=f1+f2;

f1=f2;

f2=f3;

}

}

else // if points not present in fibonacci series

{

points=points/2;

}

// checking this round is last round or not

if(i==rounds)

{  

// if yes then print final score

cout<<"Final score: "<<endl;

cout<<points;

}

else // otherwise print current score

cout<<"Current points: "<<points<<endl;

}

}

Sample Outputs

CAUsersAKSHAnDesktop\Usern a me-3A.exe How many rounds? Current points 10 Choose (a) add 1 point, (b) add 2 points .. Current points: 5 Choose (a) add 1 point, (b) add 2 points .. Current p Choose (a) add 1 point, (b) add 2 points points: ... Final score: 31

Add a comment
Know the answer?
Add Answer to:
3. You should test your program on other test cases (tdhat you make up) as well....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program which implements a dice game. Name your program file 'YourUsernameA105.py, e.g. afer023A1Q5.py. The...

    Write a program which implements a dice game. Name your program file 'YourUsernameA105.py, e.g. afer023A1Q5.py. The aim of the game is to reach a score as close as possible to 100 (but not over 100) in three rounds. Each round consists of throwing five random dice, the user then chooses two of the dice values where the two dice values chosen form a two digit score which is added to the user's current total, e.g., if the user first chooses...

  • MAKE SURE YOU TEST THE PROGRAM FISRT. DON'T PUT THE CODE WITHOUT TESTING. MAKE SURE ALL...

    MAKE SURE YOU TEST THE PROGRAM FISRT. DON'T PUT THE CODE WITHOUT TESTING. MAKE SURE ALL THE STEPS ARE FOLLOWED IN CORRECT MANNER ONLY USE VISUAL STUDIO C# CONSOLE APPLICATION Use File IO (NO JAVA CODING) Create a C# Console program that will demonstrate the use of File IO, Arrays, and Classes. This assignment has a number of requirements. Carefully read the document and note all the requirements. Also keep in mind that many of the requirements for this assignment...

  • Your mission in this programming assignment is to create a Python program that will take an...

    Your mission in this programming assignment is to create a Python program that will take an input file, determine if the contents of the file contain email addresses and/or phone numbers, create an output file with any found email addresses and phone numbers, and then create an archive with the output file as its contents.   Tasks Your program is to accomplish the following: ‐ Welcome the user to the program ‐ Prompt for and get an input filename, a .txt...

  • Hello. I am using a Java program, which is console-baed. Here is my question. Thank you....

    Hello. I am using a Java program, which is console-baed. Here is my question. Thank you. 1-1 Write a Java program, using appropriate methods and parameter passing, that obtains from the user the following items: a person’s age, the person’s gender (male or female), the person’s email address, and the person’s annual salary. The program should continue obtaining these details for as many people as the user wishes. As the data is obtained from the user validate the age to...

  • in java Complete Program that simulates a login procedure. The program reads a list of names,...

    in java Complete Program that simulates a login procedure. The program reads a list of names, email addresses and passwords from a file p3.txt. Store the information in parallel array lists names, emails and passwords. Your program will prompt the user for their email address. If the email is not in the system, prompt the user to try again. Provide the option to quit. If the email is found in the system, prompt the user to enter their password. After...

  • In this assignment, you will create an application that holds a list of contact information. You ...

    In this assignment, you will create an application that holds a list of contact information. You will be able to prompt the user for a new contact, which is added to the list. You can print the contact list at any time. You will also be able to save the contact list. MUST BE IN PYTHON FORMAT Create the folllowing objects: ContactsItem - attributes hold the values for the contact, including FirstName - 20 characters LastName - 20 characters Address...

  • In this assignment, you will create an application that holds a list of contact information. You...

    In this assignment, you will create an application that holds a list of contact information. You will be able to prompt the user for a new contact, which is added to the list. You can print the contact list at any time. You will also be able to save the contact list. Must Be In Python Format Create the following objects: ContactsItem - attributes hold the values for the contact, including FirstName - 20 characters LastName - 20 characters Address...

  • Write a program called printGPA. The program should contain at least 3 methods: main, gradeAverage, and...

    Write a program called printGPA. The program should contain at least 3 methods: main, gradeAverage, and letterGrade. The user will type a line of input containing the student's name, then a number that represents the number of scores, followed by that many integer scores (user input is in bold below). The data type used for the input should be one of the primitive integer data types. Here are two example dialogues: Enter a student record: Maria 5 72 91 84...

  • This C++ Program should be written in visual studio 2017 You are to write a program...

    This C++ Program should be written in visual studio 2017 You are to write a program that can do two things: it will help users see how long it will take to achieve a certain investment goal given an annual investment amount and an annual rate of return; also, it will help them see how long it will take to pay off a loan given a principal amount, an annual payment amount and an annual interest rate. When the user...

  • 1) Echo the input: First, you should make sure you can write a program and have...

    1) Echo the input: First, you should make sure you can write a program and have it compile and run, take input and give output. So to start you should just echo the input. This means you should prompt the user for the plaintext, read it in and then print it back out, with a message such as "this is the plaintext you entered:". [4 points, for writing a working program, echoing the input and submitting the program on the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT