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.
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:




Project [2]: Expressions and Operators Project Goals The goal of this project is to: 1. Get...
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 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 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 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 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...
The project in C is to create a game in which a player goes through a series of rooms in which they can find a prize or a monster to fight. Game Rules: • A player will enter the number of rooms (greater than 1) they want to endure. The program will dynamically allocate an array of Rooms and populate it with prizes and monsters. Then, the player will enter each room in which an action will occur: o If...
CS 215 Program Design, Abstraction, and Problem Solving Programming Project #3 INTRODUCTION The goal of this programming project is to enable the student to practice designing a program that solves a problem using a class and a linked-list and developing a C++ program to implement the solution. PROJECT TASKS 1. Read the problem definition below and then analyze it before designing a solution. You will produce a document (external documentation) of this definition, analysis, and design. 2. Write a C++...
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 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...