在int
main中声明的所有变量在int
pickword中不起作用。它只是说“variable not declared in this scope
”。当我在int
main之前声明所有变量时,此问题消失。但我尽量避免使用全局变量,但静态字没有做任何事情变量未在范围内声明
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
pickword();
int main()
{
static struct word
{
string indefSing;
string defSing;
string indefPlural;
string defPlural;
};
static word aeble = {"aeble", "aeblet", "aebler", "aeblerne"};
static word bog = {"bog", "bogen", "boger", "bogerne"};
static word hund = {"hund", "hunden", "hunde", "hundene"};
static string promptform;
static string wordform;
static word rightword;
void pickword();
cout << "Decline the word " << rightword.indefSing << "in the " << promptform << endl;
return 0;
}
void pickword()
{
cout << "welcome to mr jiggys plural practice for danish" << endl;
pickword();
using namespace std;
srand(time(0));
int wordnumber = rand()% 3;
switch (wordnumber) //picks the word to change
{
case 0:
rightword = aeble;
break;
case 1:
rightword = bog;
break;
case 2:
rightword = hund;
break;
};
int wordformnumber = rand()% 3;
switch (wordformnumber) //decides which form of the word to use
{
case 0:
wordform = rightword.defSing;
promptform = "definite singular";
case 1:
wordform = rightword.indefPlural;
promptform = "indefinite plural";
case 2:
wordform = rightword.defPlural;
promptform = "indefinite Plural";
};
}
无关:pickword的'的无限递归()'是在制造一个火车事故。我希望你喜欢这个受欢迎的消息,因为你即将看到一大堆*。 – WhozCraig 2014-10-12 07:21:58