【解決方法】なぜこれが機能しないのですか

[ad_1]

C++
if(weapon == 1){
		damage = 3 + (rand() % 20);
		dpm = damage*60;
		cs = dpm;
		cout << "Dreadlord Sword >> DPS = " << damage << " >> DPM >> " << dpm << endl;
		cin.get();
		time = time -1;
		while(time >= 0){
			dpm = dpm*multi;
			cout << endl << endl << endl << "Minute: " << multi << endl <<"Damage: "<< dpm << endl << endl;
			cout << "--Training Dummy-- -- HP: " << hp - dpm << endl;
			cin.get();
			multi = multi + 5;
			time = time - 5;
			dpm = cs;
		}
	
	int num = 1, fact, rawr, c1, gold;
	cout << "---Duck's Game---" << endl << endl << endl << endl << endl << endl << endl;
	cout << "Hi There! We challenge you to complete our 10 trials to get the prize of 1 Million Coins!" << endl << " <1> Sure! " << endl << " <2> No Thanks" << endl << ">> ";
	cin >> c1;
	while(c1 != 1 && c1 != 2){
		cout << "Uhm, what? " << endl << ">> ";
		cin >> c1;
	}
	if(c1 == 1){
		cout << "Yay! Well then step right in to your first trial. Oh and by the way you'll need this later...'" <<  endl << endl << "---RUSTY SWORD---" << endl << "Item Damage: ??? " << endl << "Old Worn Out Sword" << endl << endl << "----------DUNGEON ROOM 1----------" << endl << endl;
		cin.get();
		cout << "Troll: YOU DARE STEP IN MY ROOM? YOU FOOL! YOU WILL PAY THE ULTIMATE PRICE";
		cin.get();
		cout << "* You remember the sword the gamemaster gave you earlier. *";
		cin.get();
		cout  << " You can only get 1 good strike in so you have to really think about where you hit the troll! Entering a number now will be your damage number. ";
		cin.get();
		cout << " The troll has miserably low defense so hitting him will deal the factorial of the number you give" << endl << endl << "Enter your damage: " << endl << ">> ";
		cin >> rawr;
		while(rawr<0){
			cout << "What? You can't deal negative damage!";
			cin >> rawr;
		}
		fact = rawr;
		while(fact>0){
			num = fact*num;
			fact = fact-1;
		}
		cout << "You deal " << num << " damage!" << endl ;
		
		if (num < 15){
			cout << "Oh, you didn't kill him..." << endl << "----GAME OVER----";
			exit(1);
			
		} else {
			cout << "You killed him! " << endl << "+5 Coins!";
			cin.get();
			gold = gold + 5;
		}
	} else {
		cout << "Oh Ok.";
		exit(1);
	}
	
	
	
	
	
	// EVEN NOW OR NUMBER TWO
	int n1, n2, even, odd;
	cout << "* Proceeding to the next room *" << endl << endl << "----------DUNGEON ROOM 2----------" << endl << endl;
	cin.get();
	cout << "You see a sphinx in the room.";
	cin.get();
	cout << "Suddenly it speaks!" << endl << endl << "Sphinx: TRAVELLER! WELCOME TO MY LABYRINTH, I HAVE PROVIDED YOU WITH TWO CLANS THE MEMBERS ARE SCATTERED AND THE CLAN OF TEN ONLY HAS MEMBERS THAT HAVE EVEN SHIRTS AND THE CLAN OF SEVEN ONLY HAS MEMBERS THAT HAVE ODD SHIRTS";
	cin.get();
	cout << "Sphinx: I WILL TELL YOU TWO NUMBERS. YOU HAVE TO GET ALL THE MEMBERS BACK IN THEIR PROPER CLANS! THESE TWO NUMBERS SERVE AS THE AMOUNT OF MEMBERS ARE THERE THE WITH THEIR SHIRTS";
	cin.get();
	cout << "Sphinx: THE SMALLEST NUMBER ON A PERSON'S SHIRT IS " << endl << ">> ";
	cin >> n1;
	cout << "Sphinx: THE BIGGEST NUMBER ON A PERSON'S SHIRT IS" << endl << ">> ";
	cin >> n2;
	while(n2 >= n1 ){
		if (n2 % 2 == 0){
			cout << endl << n2;
			even = even + 1;
		} else {
			odd = odd + 1;
		}
		n2 = n2 - 1;	
	}
	cout << endl << "You: Easy! There is " << odd << " amount of members of the clan of seven and " << even << " amount of members of the clan of ten!" << endl;
	cin.get();
	cout << "Sphinx: SMART TRAVELLER, I SHALL LET YOU PASS, ALSO TAKE MY TREASURE";
	cin.get();
	cout << "+10 Coins!";
	gold = gold + 10;
	
	
	
	
	
	// CALORIES BURNED OR NUMBER THREE
	// Ma'am I changed Calories with dpm (Damage per minute) but everything else is basically the same! Hope you count this...
	int prod, r, k, l, hp = 99999, damage, php = 100, time, weapon, dpm, multi = 5, cs;
	cout << endl << endl << "----------DUNGEON ROOM 3----------" << endl << endl;
	cin.get();
	cout << "Tour Guide: Oh! It's been a while since someone made it to this stage...";
	cin.get();
	cout << "Tour Guide: Most people died to the orc or got the wrong answer to the sphinx! But this is our humble abode.";
	cin.get();
	cout << "Tour Guide: This serves as a resting place for adventurers we have our tavern and our shop...";
	cin.get();
	cout << "Tour Guide: Let's go to the shop first";
	cin.get();
	cout << "Shopkeeper: Hi there! I'm here to sell you some artifacts..." << endl << "<1> Dreadlord Sword					<2> Shadow Assassin Set					<3> Wand of Atonement";
	cout << endl << "*Dreadlord Sword is the only one in your budget*" << endl << "Can I take the dreadlord sword please?";
	cin.get();
	cout << "Shopkeeper: Sure!" << endl << "-15 Gold";
	cin.get();
	gold = gold-gold;
	cout << "Tour Guide: Oh wow! You actually bought something. " << endl << "Tour Guide: You must be feeling tired, do you wanna rest in the tavern. " ;
	cin.get();
	cout << "You: No I'm not, I'll test out this sword first. I'll come with you later" << endl << "Tour Guide: Oki, tell me when you wanna sleep though. " << endl << endl;
	cin.get();
	cout << "How long do you want to practice? " << endl << ">> ";
	cin >> time;
	while(time > 30 || time % 5 != 0){
		cout << "Time limit of 30 minutes and it has to be an interval of 5!" << endl << ">> ";
		cin >> time;
	}
	cout << "--Training Dummy-- -- HP: " << hp << endl << "	Moves:" << endl << "	N/A" << endl << endl;
	cout << "--You-- -- --HP: " << php << endl << "	Weapon:" << endl << "<1>	DreadLord Sword" << endl << "<2>	Rusty Sword";
	cout << endl << "What weapon will you use?" << endl << ">> ";
	cin >> weapon;
	if(weapon == 1){
		damage = 3 + (rand() % 20);
		dpm = damage*60;
		cs = dpm;
		cout << "Dreadlord Sword >> DPS = " << damage << " >> DPM >> " << dpm << endl;
		cin.get();
		time = time -1;
		while(time >= 0){
			dpm = dpm*multi;
			cout << endl << endl << endl << "Minute: " << multi << endl <<"Damage: "<< dpm << endl << endl;
			cout << "--Training Dummy-- -- HP: " << hp - dpm << endl;
			cin.get();
			multi = multi + 5;
			time = time - 5;
			dpm = cs;
		}
	} else {
		damage = 1 + (rand() % 3);
		dpm = damage*60;
		cs = dpm;
		cout << "Rusty Sword >> DPS = " << damage << " >> DPM >> " << dpm << endl;
		cin.get();
		time = time -1;
		while(time >= 0){
			dpm = dpm*multi;
			cout << endl << endl << endl << "Minute: " << multi << endl <<"Damage: "<< dpm << endl << endl;
			cout << "--Training Dummy-- -- HP: " << hp - dpm << endl;
			cin.get();
			multi = multi + 5;
			time = time - 5;
			dpm = cs;
		}
	}
	
	
	
	//HOTEL OCCUPANCY OR NUMBER FOUR
	// Hotel is replaced with tavern! Btw
	
	float h1, h2, rl, rt , ht , htt, ch = 0;
	float h9;
	cout << endl << "That took a long time! Time to rest..."; 
	cin.get();
	cout << endl << "Tour Guide: Ah, there you are traveller! The tavern is already filled up...";
	cin.get();
	cout << endl << "You: Oh no, is there any way I can squeeze in?";
	cin.get();
	cout << endl << "Tour Guide: Not really, but you can look at the tavern arrangements and check if any rooms are occupied";
	cin.get();
	cout << endl << "Landlord: Hi, sorry but we're filled up at the moment. Please come again tomorrow and see";
	cin.get();
	cout << endl << "You: Can I see the tavern schematic so that I can see the occupied and unoccupied rooms?";
	cin.get();
	cout << endl << "Landlord: Sure!" << endl << "You: How many floors are there?";
	cin.get();
	cout << "Landlord: There are ___ amount of floors" <<  endl << ">> ";
	cin >> h1;
	h2 = h1;
	while(h2 != 0){
		ch = ch + 1;
		h2 = h2-1;
		cout << "You: How many rooms are in floor " << ch << "?"<< endl << ">> ";
		cin >> rl;
		cout << "You: How many occupied rooms are in floor " << ch << "?" << endl << ">> ";
		cin >> ht;
		while (ht > rl){
			cout << "Invalid number! That's more occupied rooms than there are rooms...'" << endl << ">> ";
			cin >> ht;
		}
		rt = rt + rl;
		htt = htt + ht;
	}
	h9 = (htt/rt)*100;
	if (htt != 100){
	 	cout << "Ah! So there is an empty room infact there is " << htt << " amount of empty rooms meaning you have a occupancy rate of " << h9 << "%" << endl << " So, can I sleep in one of the rooms?";
	 	cin.get();
		cout << endl << "Landlord: Ok fine! Sure";
		cin.get();
	} else {
		cout << "You: Oh... Fine I'll sleep outside then";
	}
	
	
	
	
	// COUNT POSITIVE AND NEGATIVE NUMBERS OR NUMBER 5!
	
	
	int x, y, z = 0, w = 0;
	cout << "After your rest, you feel like you should go to the next room so you bid your goodbyes and enter dungeon room 4" << endl << endl << endl << "----------DUNGEON ROOM 4----------" << endl << endl <<endl;
 cin.get();
="" cout="" <<="" "there's="" nothing="" in="" the="" room="" but="" a="" stone="" puzzle="" engraved="" is"="" endl="" "-i="" will="" tell="" you="" 10-20="" numbers="" then="" must="" me="" how="" many="" negative="" there="" are="" and="" positive="" are-";
="" "how="" do="" want="" to="" input?"="" "="">> ";
	cin >> x;
	while(x > 20 || x < 10){
		cout << "Invalid Number! Try again..." << endl << ">> ";
		cin >> x;
	}
	cout << "You go to the stone tablet and enter " << x << " numbers";
	while(x != 0){
		x = x-1;
		cout << endl << "ENTER YOUR NUMBER! " << endl << ">> ";
		cin >> y;
		if(y > 0){
			z = z + 1;
		} else {
			w = w + 1;
		}
	}
	cout << "You: Uhh, I think there are " << z << " amount of positive numbers and " << w << " amount of negative numbers";
	cin.get();
	cout << endl << "The stone doors open";
	cin.get();
	cout << "+10 gold";
	gold = gold + 10;
	
	// BOSS FIGHT! NO PARTICULAR NUMBER...
	
	float mons, nm, dta, lp = 250, turn = 1, ldmg, vline;
	float modi;
	php = 100;
	cout << endl << endl << endl << "----------DUNGEON ROOM 5----------" << endl << endl <<endl;
 cin.get();
="" cout="" <<="" "...";
="" "you="" hear="" faint="" footsteps";
="" "footsteps="" get="" louder";
="" "???:="" traveller...="" ";
="" "...goodbye"="" endl;
="" "-----battle-initiated-----"="" endl="" "--livid--="" --hp="" "="" lp="" ???="" "--you--="" --="" --hp:="" php="" weapon:"="" "<1="">	DreadLord Sword" << endl << "<2>	Rusty Sword";
	cout << endl << "What weapon will you use?" << endl << ">> ";
	cin >> weapon;
	while(weapon != 1){
		cout << "Your senses doesn't let you use the weak sword! " << endl << ">> ";
		cin >> weapon;
	}
	if(weapon == 1){
		while(php != 0 && lp != 0){
			if(turn = 1){
				damage = 3 + (rand() % 20);
				cout << " <1> Great Slash " << endl << " <2> Dreadlord " << endl << " <3> Slash " << endl << ">> ";
				cin >> mons;
				while(mons > 3 || mons < 1){
					cout << " <1> Great Slash " << endl << " <2> Dreadlord " << endl << " <3> Slash " << endl << ">> ";
					cin >> mons;
				}
				if (mons = 1){
					modi = 0 + (rand() % 2) * damage;
					if(modi = 0){
					cout << endl << "You have been paralyzed by fear" << endl;
				} else {
					cout << endl << "You have dealt " << modi << " amount of damage" << endl;
				}
				lp = lp - modi;
				cout << "--Livid-- --HP " << lp << endl;
				cout << "--YOU-- --HP " << php << endl;
				turn = turn - 1;
				} else if (mons = 2){
					modi = 1 + (rand() % 2) * damage;
					cout << endl << "You have dealt " << modi << " amount of damage" << endl;
					lp = lp - modi;
					cout << "--Livid-- --HP " << lp << endl << endl;
					cout << "--YOU-- --HP " << php << endl << endl;
					turn = turn - 1;
				} else {
					cout << endl << "You have dealt " << modi << " amount of damage" << endl;		
					lp = lp - damage;
					cout << "--Livid-- --HP " << lp << endl << endl;
					cout << "--YOU-- --HP " << php << endl << endl;
					turn = turn - 1;
				}
				} else {
				ldmg = 5 + (rand() % 10);
				vline = 1 + (rand() % 5);
				if (vline = 1){
					cout << "Livid: You shall know death!" << endl << "Livid dealt " << ldmg << "!";
					cout << "--Livid-- --HP " << lp << endl;
					cout << "--YOU-- --HP " << php << endl;
					turn = turn + 1;
				} else if(vline = 2){
					cout << "Livid: Fear me Traveller..." << endl << "Livid dealt " << ldmg << "!";
					cout << "--Livid-- --HP " << lp << endl;
					cout << "--YOU-- --HP " << php << endl;
					turn = turn + 1;
				} else if(vline = 3){
					cout << "Livid: I am the beginning, I am the end" << endl << "Livid dealt " << ldmg << "!";
					cout << "--Livid-- --HP " << lp << endl;
					cout << "--YOU-- --HP " << php << endl;
					turn = turn + 1;
				} else if(vline = 4){
					cout << "Livid: Who will you cry for? once you know you will die" << endl << "Livid dealt " << ldmg << "!";
					cout << "--Livid-- --HP " << lp << endl;
					cout << "--YOU-- --HP " << php << endl;
					turn = turn + 1;
				}	else{
					cout << "Livid: To dust..." << endl << "Livid dealt " << ldmg << "!";
					php = php - ldmg;
					cout << "--Livid-- --HP " << lp << endl;
					cout << "--YOU-- --HP " << php << endl;
					turn = turn + 1;
				}
	
			}
		}
	}
	if(php = 0){
		cout << endl << "...";
		cin.get();
		cout << endl << "...";
		cin.get();
		cout << endl << "...";
		cin.get();
		cout << endl << "Livid: No...";
		cin.get();
		cout << endl << "Livid: Pick it up";
		cin.get();
		cout << endl << "You: What?";
		cin.get();
		cout << endl << "Livid: I said pick it up!";
		cin.get();
		cout << endl << "Livid: Pick it up and leave this place...";
		cin.get();
		cout << endl << "Livid dissappears to the shadows once again, he lets you pass...";
	} else {
		cout << endl << "Livid: No, NO! Not again... Not Him";
		cin.get();
		cout << endl << "Thunder strikes livid leaving him burnt and dead...";
		cin.get();
		cout << "--------BATTLE WON!--------" << endl;
		cout << "+30 Gold ";
	}
}
	
	// FRANKENSTEIN'S MONSTER OR NUMBER 6

私が試したこと:

エラーは C:\Users\ZACK\OneDrive\Documents\Asirit_Problem_Set_2.cpp です [Error] ‘rand’ は関数として使用できません

解決策 2

もちろん rand 関数として使用できます。 ただし、含める必要があります stdlib.h (また cstdlib) コンパイラにそれを認識させるために。

解決策 1

私たちはあなたの完全なコードを持っていません. rand アプリでエラーをスローしています。

推測では、コードのどこかで、あなたが私たちに示していない変数を宣言しています rand そしてその定義は「マスキング」です std::rand 呼び出そうとすると機能します。

そのため、エラー メッセージをよく見てください。それを特定するのに役立つ行と列の情報が含まれているので、その理由を探してください。 これは役立つかもしれません: 問題を解決するコードの書き方、初心者向けガイド パート 2: 構文エラー[^]

コーディング中に毎日、おそらく 1 日に何度も構文エラーが発生することを予期する必要があります。経験の豊富さに関係なく、誰もがそうです。 変数やキーワードのスペルを間違えることがあります。 文字列やコード ブロックを閉じるのを忘れることがあります。 猫があなたのキーボードの上を歩いて、とても奇妙なことをタイプすることがあります。 メソッド呼び出しに必要なパラメーターの数を忘れてしまうことがあります。

我々はすべての間違いを犯します。

そして、私たちは皆そうしているので、構文エラーを修正する必要があります。他の人が修正してくれるのを待つよりも、方法を学んで自分で修正する方がはるかに迅速です! したがって、エラー メッセージの読み方と、コンパイラが間違っていると言っていることに照らして記述されたコードを解釈する方法を学ぶことに少し時間を費やしてください。

[ad_2]

コメント

タイトルとURLをコピーしました