3. Create a Program From Pseudocode (TCOs 1, 2, 4, 5, and 6) This exercise will
ID: 3853148 • Letter: 3
Question
3. Create a Program From Pseudocode (TCOs 1, 2, 4, 5, and 6)
This exercise will be to use pseudocode (in the form of comments) to write a program that creates and initializes the variables for a computer role-playing game character generator. This will only set up the variables. The difference from last week is that you must put your character attributes in a structure. You can make up your own variable names.
Here is the pseudocode.
// Week 2 Assignment-3
// Description: CRPG Character attributes using a struct
//----------------------------------
//**begin #include files************
#include <iostream> // provides access to cin and cout
//--end of #include files-----------
//----------------------------------
//**begin global constants**********
//--end of global constants---------
//----------------------------------
using namespace std;
//----------------------------------
//**begin main program**************
int main()
{
//**Enter code staring here
// Create structure
// initialize structure data members
// character ID [integer] initialized to 0
// strength [integer] initialized to 80
// armor [integer] initialized to 70
// health [float] initialized to 1.0f
// flag to indicate if the character is dead or alive [boolean] initialized to true
// Print out each of the data members in the structure.
//**End of your code
// Wait for user input to close program when debugging.
cin.get();
return 0;
}
//--end of main program-------------
//----------------------------------
Explanation / Answer
Program:
________
#include<iostream>
using namespace std;
int main()
{
//** creating structure and initializing structure variables
struct user_struct
{
int characterID = 0;
int strength = 80;
int armor = 70;
float health = 1.0;
boolean flag = true;
}us;// us is a structure object
//** printing each structure variable
cout<<us.characterID<<endl;
cout<<strength<<endl;
cout<<us.armor<<endl;
cout<<us.health<<endl;
cout<<us.flag<<endl;
cin.get();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.