Question

In: Computer Science

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.

Solutions

Expert Solution

/******************************************************************************

Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>

int main()
{ //store points in varible

int HealthPoint=10;
float WealthPoint=0.00;
  
//take accept input
int input;

//boolean for checking conditions
int have_sword=0;
int have_shield=0;
  
printf("You’re walking through the woods and come upon a chest. Do you open it? 1 – yes 2 - no");
scanf("%d",&input);
if(input ==1) // chooses to open
{
WealthPoint+=3.75;
have_sword=1;
printf("You have got 3.75 Wealth Point and sword\n");

  
}else if(input ==2){ // refuses to open
printf("You have lost Health Point\n");

HealthPoint--;
}
printf("You’re walking through the woods and come upon a bag. Do you open it? 1 – yes 2 - no");
scanf("%d",&input);
if(input ==1) // chooses to open
{
WealthPoint+=5.15;
have_shield=1;
printf("You have got 5.15 Wealth Point and shield\n");

  
}else if(input ==2){ // refuses to open
printf("You have lost Health Point\n");

HealthPoint--;
}
printf("You’re walking through the woods and Do you want to engage in a battle with an ogre? 1 – yes 2 - no");
scanf("%d",&input);
if(input ==1) // chooses to fight
{
if(have_sword==0||have_shield==0){
HealthPoint=0;
printf("You have lost all Health Point\n");

}
if(have_sword==1&&have_shield==0){
HealthPoint=0;
printf("You have lost all Health Point\n");

}
if(have_sword==0&&have_shield==1)
{ printf("You have not gain Health Point or Wealth Point\n");
}
if(have_sword==1&&have_shield==1){
HealthPoint+=12;
printf("You have got 12 Health Point\n");

}

  
}else if(input ==2){ // refuses to fight
HealthPoint=0;
printf("You have lost all Health Point\n");

}
  
// check whether wins or losses game
if (HealthPoint >10 && WealthPoint >4.25){
printf("You have won the game and ");
printf("You have %d HealthPoint and %f WealthPoint\n", HealthPoint,WealthPoint);
}
else{
printf("You have loss the game");
}
  
  
return 0;
}
==================================================================

Output:

akshay@akshay-Inspiron-3537:~$ gcc game.c
akshay@akshay-Inspiron-3537:~$ ./a.out
You’re walking through the woods and come upon a chest. Do you open it? 1 – yes 2 - no1
You have got 3.75 Wealth Point and sword
You’re walking through the woods and come upon a bag. Do you open it? 1 – yes 2 - no1
You have got 5.15 Wealth Point and shield
You’re walking through the woods and Do you want to engage in a battle with an ogre? 1 – yes 2 - no1
You have got 12 Health Point
You have won the game and You have 22 HealthPoint and 8.900000 WealthPoint


Related Solutions

Consider simple infix expressions that consist of single-digit operands; the operators +, -, *, and /;...
Consider simple infix expressions that consist of single-digit operands; the operators +, -, *, and /; and the parentheses. Assume that unary operators are illegal and that the expression contains no embedded spaces. Design and implement a class of infix calculators. The class should have the following members: Private members: a string to store an infix expression for evaluation. a private member function that checks if an infix expression is well formed. (A well formed expression consists of single-digit operands;...
Consider simple infix expressions that consist of single-digit operands; the operators +, -, *, and /;...
Consider simple infix expressions that consist of single-digit operands; the operators +, -, *, and /; and the parentheses. Assume that unary operators are illegal and that the expression contains no embedded spaces. Design and implement a class of infix calculators. The class should have the following members: Private members: a string to store an infix expression for evaluation. a private member function that checks if an infix expression is well formed. (A well formed expression consists of single-digit operands;...
C++ OOP Make a program to evaluate infix arithmetic expressions containing integer operands and the operators...
C++ OOP Make a program to evaluate infix arithmetic expressions containing integer operands and the operators + (addition), - (subtraction), * (multiplication), / (division) and pairs of parentheses, properly nested. Use the following two-stack algorithm (by E. W. Dijkstra): If the next token in the expression is an integer, push the integer onto the value stack. If the next token in the expression is an operator, If the operator stack is empty or the priority of the operator is greater...
What is the goal of Cluster-on-demand? if there are goals, Why?
What is the goal of Cluster-on-demand? if there are goals, Why?
Explain the role of goals and goal setting in organizations
Explain the role of goals and goal setting in organizations
Create your OWN GOMS technique model. (Goals, operators, methods and selection)
Create your OWN GOMS technique model. (Goals, operators, methods and selection)
Three of the seven goals in the National Plan to Improve Health Literacy are: Goal 1:...
Three of the seven goals in the National Plan to Improve Health Literacy are: Goal 1: Develop and disseminate health and safety information that is accurate, accessible, and actionable Goal 2: Promote changes in the healthcare delivery system that improve information, communication, informed decision-making, and access to health services Goal 3: Incorporate accurate and standards-based health and developmentally appropriate health and science information and curricula into child care and education through the university level Describe two different ways to fulfill...
**please make sure this is original work** Project 1 The goals are: Project 1 - classes,...
**please make sure this is original work** Project 1 The goals are: Project 1 - classes, text data file, GUI, searching  Define and implement appropriate classes, including: o instance and class variables, o constructors, o toString methods, and o other appropriate methods.  Read data from a text file: o specified at run time,  JFileChooser jfc = new JFileChooser ("."); // start at dot, the current directory o using that data to create instances of the classes, o...
The most important goal of transfer pricing should be to: a. maximize the goals of the...
The most important goal of transfer pricing should be to: a. maximize the goals of the buying division. b. maximize the goals of the selling division. c. maximize the goals of the employees working in those divisions. d. maximize the goals of the company as a whole.
Write short notes on the following: 1.output goals 2.Adaptation goals 3.Management goals 4.Multivational goals 5.Positional goals
Write short notes on the following: 1.output goals 2.Adaptation goals 3.Management goals 4.Multivational goals 5.Positional goals
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT