在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