Question

Project [2]: Expressions and Operators Project Goals The goal of this project is to: 1. Get...

Project [2]: Expressions and Operators
Project Goals
The goal of this project is to:
1. Get students familiar with expressions and operators.
Important Notes:
1. Formatting: Make sure that you follow the precise recommendations for the output content and formatting. For example, do not change the text from
“You’re walking through the woods and come upon a chest.
Do you open it? 1 – yes 2 - no” to
“Do you open the chest? ”.
Your assignment will be auto-graded and any changes in formatting will result in a loss in the grade.
2. Comments: Header comments are required on all files and recommended for the rest of the program. Points will be deducted if no header comments are included.
Program
Save your program as adventure.c
Write a program that will allow the user to play a simple Choose Your Own Adventure game.
The program should behave as follows:
The user starts out with 10 Health Points and 0.0 Wealth Points. The user encounters a series of choices which affect their Health and Wealth Point totals. In the end, if their Health Points are over 10 and their Wealth Points are over 4.25, they win! Otherwise they lose.
The first choice comes when the user encounters a chest. If they open the chest, they gain 3.75 Wealth Points and a sword. If they don’t, they stub their toe and lose a Health Point.
The second choice comes when the user encounters a bag. If they open the bag, they gain 5.15 Wealth Points and a shield. If they don’t, they get a blister and lose a Health Point.
The final choice is whether to engage in a battle with an ogre. If they choose to fight and they don’t have a sword or shield, they lose all their Health Points. If they choose to fight and they have only the sword, they lose all their Health Points. If they choose to fight and they have only the shield, they don’t lose or gain any Health Points. If they choose to fight and have both their sword and shield, they gain 12 Health Points. If they choose to flee, they trip and fall, get stomped on by the ogre and lose all their Health Points.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program :

#include <stdio.h>
#include <stdlib.h>

int
main ()
{
float health_pt, wealth_pt;
int choice;
  
// initially the player doesnt have a sword or a sheild . So both are set to 0
int sword = 0;
int shield = 0;
  
// initializing health points and wealth points
health_pt = 10.0;
wealth_pt = 0.0;
  
//player encounters a chest
printf("You are walking through the chests and come upon a chest \nDo you want to open it? 1-yes 2-no \n");
scanf ("%d", &choice) ;
if (choice == 1)
{
wealth_pt = wealth_pt + 3.25;
//player found a sword so its set to 1
sword = 1;
printf("You gained 3.25 wealth points and found a sword!\n");
//choice is set to zero
choice = 0;
}
else if (choice == 2)
{
printf("You stubbed your toe and lost a health point\n");
health_pt = health_pt - 1;
//choice is set to zero
choice = 0;
}
else
{
printf("Invalid choice\n");
exit(0);
}
  
  
// player encounters a bag
printf("\nYou found a bag! \nDo you want to open it? 1-yes 2-no \n");
scanf ("%d", &choice) ;
if (choice == 1)
{
wealth_pt = wealth_pt + 5.15;
//player found a sword so its set to 1
shield = 1;
printf("You gained 5.15 wealth points and found a shield!\n");
//choice is set to zero
choice = 0;
}
else if (choice == 2)
{
printf("You got a blister and lost a health point\n");
health_pt = health_pt - 1;
//choice is set to zero
choice = 0;
}
else
{
printf("Invalid choice\n");
exit(0);
}
  
/* Conditions given :
The final choice is whether to engage in a battle with an ogre.
If they choose to fight and they don’t have a sword or shield, they lose all their Health Points.
If they choose to fight and they have only the sword, they lose all their Health Points.
If they choose to fight and they have only the shield, they don’t lose or gain any Health Points.
If they choose to fight and have both their sword and shield, they gain 12 Health Points.
If they choose to flee, they trip and fall, get stomped on by the ogre and lose all their Health Points.
*/   
printf("\nDo you want to engage in a battle with an ogre . 1-yes 2-no\n");
scanf ("%d", &choice) ;
if (choice == 1)
{
if(sword == 0 && shield == 0)
{
printf("You dont have sword and sheild you lost all your health points\n");
health_pt = 0;
}
else if(sword == 1 && shield ==0)
{
printf("You have a sword but not the shield");
health_pt = 0;
}
else if(sword == 0 && shield ==1)
{
printf("You have a sheild but not the sword");
}
else if(sword == 1 && shield == 1)
{
printf("You gained 12 health points");
health_pt = health_pt + 12;
}
}
else if (choice == 2)
{
printf("You fell and got stomped by the ogre");
health_pt = 0;

  
}
else
{
printf("Invalid choice\n");
exit(0);
}
  
  
printf( "\n\nHealth points = %f\nWealth points = %f\n",health_pt,wealth_pt);

/* if their Health Points are over 10 and their Wealth Points are over 4.25,
they win! Otherwise they lose. */

if(health_pt > 10.0 && wealth_pt > 4.25)
{
printf("You Won!");
}
else
{
printf("You lost");
}

return 0;
  
}

Outputs:

Add a comment
Know the answer?
Add Answer to:
Project [2]: Expressions and Operators Project Goals The goal of this project is to: 1. Get...
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
  • HIGHEST SUBMISSION Vlew All Submissions Submission 17 Submitted on 6/10/2019 12 35 PM by Jenna Saleh...

    HIGHEST SUBMISSION Vlew All Submissions Submission 17 Submitted on 6/10/2019 12 35 PM by Jenna Saleh DESCRIPTION Objectives To write a classes based on sets of specifications To write a main class to be used in a multi-class Java program To use inheritance to extend a class (optional, EC) To override methods in subclasses (optional, EC) Groups You may work with a partner on this assignment. A header comment (In every Java file) should include authors (group members) and collaborators...

  • CSC151 Stock Portfolio GUI Project Goal You are to write a GUI program that will allow...

    CSC151 Stock Portfolio GUI Project Goal You are to write a GUI program that will allow a user to buy, sell and view stocks in a stock portfolio. This document will describe the minimum expected functions for a grade of 90. Your mission is to “go and do better.” You’ll find a list of enhancement options at the end of this document. Objectives By the end of this project, the student will be able to • write a GUI program...

  • Project 3 Instructions 1. Due Date & Time: 09-26-2020 at 11:59 PM WHAT TO SUBMIT Submit...

    Project 3 Instructions 1. Due Date & Time: 09-26-2020 at 11:59 PM WHAT TO SUBMIT Submit 1 zip file containing 4 files below to iLearn by the deadline. [30 points] ● 3 JAVA Files: TableBmiPro.java, MyOwnIdea.java. DiceRoll.java [24 points] ● 1 File: Make a document that shows the screen captures of execution of your programs and learning points in Word or PDF. Please make sure you capture at least 2 executions for 1 program, so 6 screen captures and one...

  • Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQ...

    Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQUIRED for this program will use two stacks, an operator stack and a value stack. Both stacks MUST be implemented using a linked list. For this program, you are to write functions for the linked list stacks with the following names: int isEmpty (stack); void push (stack, data); data top (stack); void pop (stack); // return TRUE if the stack has no...

  • Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQ...

    Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQUIRED for this program will use two stacks, an operator stack and a value stack. Both stacks MUST be implemented using a linked list. For this program, you are to write functions for the linked list stacks with the following names: int isEmpty (stack); void push (stack, data); data top (stack); void pop (stack); // return TRUE if the stack has no...

  • C++ Programming

    PROGRAM DESCRIPTIONIn this project, you have to write a C++ program to keep track of grades of students using structures and files.You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle...

  • Write a program in the Codio programming environment that allows you to play the game of...

    Write a program in the Codio programming environment that allows you to play the game of Rock / Paper / Scissors against the computer. Within the Codio starting project you will find starter code as well as tests to run at each stage. There are three stages to the program, as illustrated below. You must pass the tests at each stage before continuing in to the next stage.  We may rerun all tests within Codio before grading your program. Please see...

  • C LANGUAGE. PLEASE INCLUDE COMMENTS :) >>>>TheCafe V2.c<<<< #include ...

    C LANGUAGE. PLEASE INCLUDE COMMENTS :) >>>>TheCafe V2.c<<<< #include <stdio.h> int main() { int fries; // A flag denoting whether they want fries or not. char bacon; // A character for storing their bacon preference. double cost = 0.0; // The total cost of their meal, initialized to start at 0.0 int choice; // A variable new to version 2, choice is an int that will store the // user's menu choice. It will also serve as our loop control...

  • IP requirements: Load an exam Take an exam Show exam results Quit Choice 1: No functionality...

    IP requirements: Load an exam Take an exam Show exam results Quit Choice 1: No functionality change. Load the exam based upon the user's prompt for an exam file. Choice 2: The program should display a single question at a time and prompt the user for an answer. Based upon the answer, it should track the score based upon a successful answer. Once a user answers the question, it should also display the correct answer with an appropriate message (e.g.,...

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