TAILIEUCHUNG - C++ Programming for Games Module I phần 3

Tham khảo tài liệu 'c++ programming for games module i phần 3', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | An if .else statement can branch execution along two separate paths one path if the condition is true or a second path if the condition is not true. However what if you need more than two execution paths For instance what if you wanted to say if A then B else if C then D else if E then F else G. This can be achieved by using several nested if. .else statements. Program shows how this might be used to initialize a player s character class in a fantasy role-playing-type game based on the character the user selected. Program Program illustrates creating multiple execution paths using nested statements. include iostream include string using namespace std int main Output some text asking the user to make a selection. cout Welcome to Text-RPG endl cout Please select a character class number. endl cout 1 Fighter 2 Wizard 3 Cleric 4 Thief Prompt the user to make a selection. int characterNum 1 cin characterNum Initialize character variables to default value. int numHitpoints 0 int numMagicPoints 0 string weaponName string className if characterNum 1 Fighter selected numHitpoints 10 numMagicPoints 4 weaponName Sword className Fighter else if characterNum 2 Wizard selected numHitpoints 4 numMagicPoints 10 weaponName Magic Staff className Wizard else if characterNum 3 Cleric selected numHitpoints 7 numMagicPoints 7 weaponName Magic Staff className Cleric else Not 1 2 or 3 so select thief. numHitpoints 8 numMagicPoints 6 52 weaponName className Short Sword Thief cout endl cout Character properties endl cout Class name className endl cout Hitpoints numHitpoints endl cout Magicpoints numMagicPoints endl cout Weapon weaponName endl Output . Welcome to Text-RPG Please select a character class number. 1 Fighter 2 Wizard 3 Cleric 4 Thief 2 Character properties Class name Wizard Hitpoints 4 Magicpoints 10 Weapon Magic Staff Press any key to continue Here we provide four different execution paths based on whether the user chose a Fighter Wizard Cleric or .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.