Closed. This question needs to be more
focused。它当前不接受答案。
想改善这个问题吗?更新问题,使其仅通过
editing this post专注于一个问题。
3年前关闭。
在C ++方面,我是一个业余爱好者,我很乐意看到我可以做些什么来改进我编写的帮助我完成AP英语功课的程序。基本上,它会打印单词的定义,您必须正确匹配它们。如果错误,则显示“错误,正确的单词是:(正确的单词)”;如果正确,则显示“ Great!”。
所以我也有一些关于为什么东西起作用的问题,我正在编码并且就像wtf一样不应该起作用,但是确实可以
(代码下方的问题)
#include <iostream>
#include <string>
#include <ctime>
#include <Windows.h>
using namespace std;
class APMC {
public:
// Array of the words
string word[56] = { "Footnote", "Blatant", "Bounded", "Assertion", "Faulty",
"Cynicism", "Compunction", "Aberration", "Degeneration", "Solemnity",
"Treatise", "Grotesque", "Exposition", "Ambiguous", "Tirades", "Appropriate",
"Ornamentation", "Prattling", "Nomenclature", "Berate", "Aesthetics", "Homiletic",
"Innate", "Merits", "Fallocious", "Jeremiads", "Cornucopia", "Enumerate", "Extraneous",
"Ineluctable", "Ascertain", "Interpolation", "Emulation", "Sanguine", "Nostalgia", "Fluted",
"Disillusion", "Derivation", "Discursive", "Digression", "Prose", "Caduceus", "Conspicuous",
"Contemptuous", "Enunciates", "Admonitions", "Alludes", "Empirical", "Abstractions", "Satiety",
"Futility", "Disparate", "Indicative", "Facetiously", "Definitively", "Abstract"};
// Array of the definitions of the words
string description[56] = { "An additional piece of information printed at the bottom of a page","Offensively loud, flagrant",
"Leaping strides", "A confident and forceful statement of fact or belief", "Not working or made correctly; having defects",
"An inclination to believe that people are motivated purely by self-interest; skepticism",
"A feeling of Guilt or moral scruple that prevents or follows the doing of something bad", "A deperature from what is normal, usual, or expected, typically an unwelcome one",
"The state or process of being or becoming degenerate; decline or deterioration", "The state or quality of being serious and dignified",
"A written work dealing formally and systematically with a subject", "A very ugly or comically distorted figure or image", "A comprehensive description and explanation of an idea or theory",
"Open to more than one interpretation; not having one obvious meaning", "A long, angry speech of criticism or accusation", "Suitable or proper in the circumstances",
"Decorative elements added to something to enhance its appearance", "Foolish or inconsequential talk", "The body or system of names used in a particular specialist field",
"Scold or criticize (Ssomeone) angrily", "A set of principles concerned with the nature and appreciation of beauty", "The art of preaching or writing sermons",
"Inborn, Natural", "The quality of being particularly good or worthy, especially to deserve praise or reward", "Based on a mistaken belief", "A long, mournful complaint or lamentation; a list of woes",
"A symbol of plenty consisting of a goat's horn overflowing with flowers, fruit, and corn", "Mention (a number of things) one by one", "Irrelevant or unrelated to the subject being dealt with",
"Unable to be resisted or avoided; inescapable", "Find (something) out for certain; make sure of", "The insertion of something of a different nature into something else",
"Effort to match or surpass a person or achievement, typically by imitation", "Optimistic or positive, especially in an aparrently bad or difficult situation",
"A sentimental longing or wistful affection for a period in the past", "Having flutes or grooves; ridged", "Disappointment resulting from the discovery that something is not as good as one believed it to be",
"The action of obtaining something from a source or origin", "Digressing from subject to subject", "A temporary departure from the main subject in speech or writing",
"Written or spoken language in its ordinary form, without metrical structure", "An ancient greek or roman herald's wand", "Clearly visible", "Showing contempt; scornful",
"Say or pronounce clearly", "A firm warning or reprimand", "Suggest or call attention to indirectly; hint at",
"Based on, concerned with, or verifiable by observeration or experience rather than theory or pure logic", "The quality of dealing with ideas rather than events",
"The feeling or state of being sated", "Pointlessness or uselessness", "Essentially different in kind; not able to be compared",
"Serving as a sign or indication of something", "Treating serious issues with deliberately inappropriate humour; flippant",
"Decisively and with authority; conclusively", "Existing in thought or as an idea but not having a physical or concrete existence" };
};
int main() {
// Is the game running?
bool isGameRunning = true;
// Casts an integer to time and stores it into random so it is for SURE random!
srand((int)time(0));
// Classes object key thing
APMC words;
// The whole program is ran in a loop, declared above
while (isGameRunning) {
// Random between 0 and 56 because there is 56 words
int random = (rand() % 56) + 0;
string userInput;
// Displays a random definition
cout << "The definition is: " << words.description[random] << endl;
cin >> userInput;
system("cls");
// This is where im confused on WHY this worked
if (userInput == words.word[random]) {
cout << "Great!" << endl;
}
else {
// Also confused on why this worked, but displays the correct answer if it is wrong
cout << "Wrong, the answer was: " << words.word[random] << endl;
}
}
return 0;
}
问题:
1.说的部分
"if (userInput == words.word[random]) {
cout << "Great!" << endl;
}"
好吧,为什么这行得通?这是偶然的,基本上说如果userInput是一个字符串,则按字符串等于数组中的单词,则匹配。但是,数组不是按数字分类的吗。0-56?那么数组如何知道userInput,它采用字符串值,与数组中的INTEGER值匹配?
它说的部分感到困惑
“ cout <<”错误,答案是:“ << << words.word [random] << endl;”
好吧,它是一个随机数吧?它怎么会记得显示时是什么单词?我肯定认为这将显示一个不同的词。我的猜测是,当它循环并在开始时声明随机部分时,它将组成新的数字。
谢谢大家,对不起,如果我措辞如此。
寻找改进!
我是一名优秀的程序员,十分优秀!