Ugh... what am I doing WRONG!

Pages: 123
Hey. I'm a nerdy bilingual girl xD

I've been getting into C++ and have made something I think is really killer :D I want to make a program for learning Japanese (my second language). I've gotten it to work for the most part but if you answer the first quiz right the first time through then the next message will show up for a half second and the whole window will close out. Maybe it's because I'm a chick but I'm pretty smart and I still don't know what the f**k I'm doing wrong in my code. If anyone (boy or girl, nerd or jock) can help me, I'd be in your debt (figuratively ;D)


Sincerely,
Samantha

PS: You can try to run it and try it for yourselves. I used MS Visual C++ 2010 Express while making and trying it.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "stdafx.h"
	
int _tmain(int argc, TCHAR* argv[])
{
	int e;  //First varible
	int fa1;  //First Answer
	int sa1; //Second Answer
	int la1; //Last Answer
	int b;
	

	//My introduction to the lesson
		printf( "LEARNING JAPANESE - Nihongo gakusyu\n\n" );
		printf( "Hello :3 I would like to welcome you to the first lesson of most likely\n");
		printf( "multiple.\n\n" );
		printf( "If you're ready to start your lesson type \"0\" then press \"enter\".\n" );
		scanf(  "%d", &e );

	if( e == 0 ) //Lesson 1
	{
		printf( "Welcome to Lesson One (Ressun ichi). Now, we'll get right into it. The\n" );
		printf( "first thing you should know is how they say \"Japan\".\n\n" );
		printf( "In romanji (japanese words written with our alphebet) it can be spelled\n" );
		printf( "\"Nippon\" but in most cases it'll be spelled \"Nihon\".\n\n" );
		printf( "But, let's add some suffixes to make that simple word into other words.\n" );
		printf( "\"Jin\" can be added to the end of any countries name to make it the name\n" );
		printf( "of that countrys' citizens. So, \"Nihonjin\" are Japanese people. Also,\n" );
		printf( "\"Go\" can be added to the end of a country's name to name the language\n" );
		printf( "origined by the country. So, \"Nihongo\" is the japanese language.\n\n" );
		printf( "So, here's a test. What do you call Spanish people in japanese.\n" );
		printf( "NOTE: Spain is spelled \"Supein\" in japan (I'll explain why later)\n" );
		printf( "1.Supeingo\n" ); //wrong
		printf( "2.Spaingo\n" ); //Very wrong
		printf( "3.Supeinjin\n\n" ); //YES!!!
		scanf(  "%d", &fa1 );
	}
	else
	{
		return (0);
	}

	if( fa1 == 3 )
	{
		printf( "HAI! That is correct, dear friend. \"jin\" is the suffix for language.\n" );
		printf( "Now, America in the japanese language is spelled \"Amerika\". Therefore,\n" );
		printf( "you are an \"Amerikajin\". Isn't that awesome :D!? Rolls of the tongue!\n\n" );
		printf( "But, you do not speak \"Amerikago\". In fact, just saying that makes\n" );
		printf( "my biligual brain want kill it. No, you speak the language of England,\n" );
		printf( "\"English\". Now in japanese, they just call english in an imformal\n" );
		printf( "chat \"Eigo\" as opposed to \"Ingurandogo\" so as to not want to pull\n" );
		printf( "the trigger XD!\n" );
		printf( "MORE COMING SOON!!\n" );
		scanf(  "%d", &b );
	}

	else if( fa1 == 2 ) //If you didn't pay attention to me at all
	{
		printf( "IIE. That is super wrong (Sorry). Please reread the lesson and question\n" );
		printf( "Try another option.\n\n" );
		scanf(  "%d", &sa1 );
	}
	else if( fa1 == 1 ) //If you chose the wrong answer
	{
		printf( "IIE. I'm sorry, but that was wrong. \"go\" is used to identify its a name\n" );
		printf( "of a language, not the name of natinality. Try another option.\n\n" );
		scanf(  "%d", &sa1 );
	}

	else
	{
		return(0);
	}

	if( sa1 == 1 ) //If you didn't pay attention to me at all
	{
		printf( "IIE. I'm sorry, but that was wrong. \"go\" is used to identify its a name\n" );
		printf( "of a language, not the name of natinality. The answer is 3.\n\n" );
		scanf(  "%d", &la1 );
	}
	else if( sa1 == 2 )
	{
		printf( "IIE. That is super wrong (Sorry). Please reread the lesson and question\n" );
		printf( "the correct answer is 3.\n\n" );
		scanf(  "%d", &la1 );
	}
	else if( sa1 == 3 ) //If you were a good student :3
	{
		printf( "HAI! That is correct, dear friend. \"jin\" is the suffix for language.\n" );
		printf( "Now, America in the japanese language is spelled \"Amerika\". Therefore,\n" );
		printf( "you are an \"Amerikajin\". Isn't that awesome :D!? Rolls of the tongue!\n\n" );
		printf( "But, you do not speak \"Amerikago\". In fact, just saying that makes\n" );
		printf( "my biligual brain want kill it. No, you speak the language of England,\n" );
		printf( "\"English\". Now in japanese, they just call english in an imformal\n" );
		printf( "chat \"Eigo\" as opposed to \"Ingurandogo\" so as to not want to pull\n" );
		printf( "the trigger XD!\n" );
		printf( "MORE COMING SOON!!\n" );
		scanf(  "%d", &b );
	}
	else
	{
		return(0);
	}

	if(  la1 == 3 )
	{
		printf( "HAI! That is correct, dear friend. \"jin\" is the suffix for language.\n" );
		printf( "Now, America in the japanese language is spelled \"Amerika\". Therefore,\n" );
		printf( "you are an \"Amerikajin\". Isn't that awesome :D!? Rolls of the tongue!\n\n" );
		printf( "But, you do not speak \"Amerikago\". In fact, just saying that makes\n" );
		printf( "my biligual brain want kill it. No, you speak the language of England,\n" );
		printf( "\"English\". Now in japanese, they just call english in an imformal\n" );
		printf( "chat \"Eigo\" as opposed to \"Ingurandogo\" so as to not want to pull\n" );
		printf( "the trigger XD!\n" );
		printf( "MORE COMING SOON!!\n" );
	}
	else
	{
		return(0);
	}
	return 0;
}
Last edited on
Please explain the variables. Why do they have names like "a" and "aa". You should use more descriptive names. Also, format your code in your post (put it in code tags.)

Unless I missed something, you did not give "aa" a value before you read it in your if-statement; when they give a correct answer you should manually set it to a value of 3 (or whatever works for your code.)
Okay. I fixed the weird varibles (thank you). I guess I made them into a's because of the way I came to get this solution. If you look at this post I have changed the "a"s to "fa1" because those are the different results you will get depending on how you answer the first question asked and so forth. Now... I'm new at this so I'll be honest I have NO idea what "code tags" are xDD If you can tell me how to do that I will.

Anyhow, please look at the revised version above.
Edit your post, highlight your code, then look to the left of the editbox. You should see a box with symbols in it (it's titled "Format:"). Click the first symbol, it looks like <>
Okay :D I did it! Win for Sammy. Now, any solutions come to mind :l?
mathhead200 wrote:
Unless I missed something, you did not give ["sa1"] a value before you read it in your if-statement; when they give a correct answer you should manually set it to a value of 3 (or whatever works for your code.)
See, but I don't think it should be. it doesn't make since to do that
Explain this C++ statement to me (not really): sa1 == 3 (I know what it means, I want you to think about what it's doing. Explaining it, even to yourself is a good way to do that.) Now... remember that when the program reaches this point, if the user answered correctly so far, you have not yet assigned a value to the variable sa1 (you should check this in case I missed something.)
Now, what do you expect sa1 == 3 to give you?
*Sigh* If you run the program, after getting past the introduction, it'll ask you a multiple choice question. when you get to that point, it you type in the number 3 then that if statement runs it's course... but if sa1 isn't equal to 3, but instead 2, then the next if statement there does it's course. Make since *Twirls her hair, trying to look hot where she isn't being smart XP*
Let's assume the user types 0 (stored in e) to start, then 3 (stored in fa1) for the first correct answer. Then they type anything (stored in b). Now we "fall through" the if else-if "chain" until the next if else-if "chain". Now this one checks the value of sa1. But what is the value of sa1? Well the answer is we don't (and can't) know; it hasn't been assigned a value yet. So sa1 may indeed equal 3... or 2, or something else like -5098712. We call this garbage data. sa1 contains garbage (whatever is left over in memory (RAM) at that location usually.)
Last edited on
*scratches head* But I'm not about to enter the b value because it closes before you can view the next window
Right, but it's still in the code... So it will expect input at that point.

The point is not the b variable. It's:
SamanthaSpeaks wrote:
if you answer the first quiz right the first time through then the next message will show up for a half second and the whole window will close out.
I'm trying to help you with that problem, skip the part about the b variable.
Last edited on
Oh *Sees her brown hair again* good, I understand. I'll try that real quick... >XP It's still breaking after you put the right answer in.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "stdafx.h"

int _tmain(int argc, TCHAR* argv[])
{
int e; //First varible
int fa1; //First Answer
int sa1; //Second Answer
int la1; //Last Answer


//My introduction to the lesson
printf( "LEARNING JAPANESE - Nihongo gakusyu\n\n" );
printf( "Hello :3 I would like to welcome you to the first lesson of most likely\n");
printf( "multiple.\n\n" );
printf( "If you're ready to start your lesson type \"0\" then press \"enter\".\n" );
scanf( "%d", &e );

if( e == 0 ) //Lesson 1
{
printf( "Welcome to Lesson One (Ressun ichi). Now, we'll get right into it. The\n" );
printf( "first thing you should know is how they say \"Japan\".\n\n" );
printf( "In romanji (japanese words written with our alphebet) it can be spelled\n" );
printf( "\"Nippon\" but in most cases it'll be spelled \"Nihon\".\n\n" );
printf( "But, let's add some suffixes to make that simple word into other words.\n" );
printf( "\"Jin\" can be added to the end of any countries name to make it the name\n" );
printf( "of that countrys' citizens. So, \"Nihonjin\" are Japanese people. Also,\n" );
printf( "\"Go\" can be added to the end of a country's name to name the language\n" );
printf( "origined by the country. So, \"Nihongo\" is the japanese language.\n\n" );
printf( "So, here's a test. What do you call Spanish people in japanese.\n" );
printf( "NOTE: Spain is spelled \"Supein\" in japan (I'll explain why later)\n" );
printf( "1.Supeingo\n" ); //wrong
printf( "2.Spaingo\n" ); //Very wrong
printf( "3.Supeinjin\n\n" ); //YES!!!
scanf( "%d", &fa1 );
}
else
{
return (0);
}

if( fa1 == 3 )
{
printf( "HAI! That is correct, dear friend. \"jin\" is the suffix for language.\n" );
printf( "Now, America in the japanese language is spelled \"Amerika\". Therefore,\n" );
printf( "you are an \"Amerikajin\". Isn't that awesome :D!? Rolls of the tongue!\n\n" );
printf( "But, you do not speak \"Amerikago\". In fact, just saying that makes\n" );
printf( "my biligual brain want kill it. No, you speak the language of England,\n" );
printf( "\"English\". Now in japanese, they just call english in an imformal\n" );
printf( "chat \"Eigo\" as opposed to \"Ingurandogo\" so as to not want to pull\n" );
printf( "the trigger XD!\n" );
printf( "MORE COMING SOON!!\n" );
}

else if( fa1 == 2 ) //If you didn't pay attention to me at all
{
printf( "IIE. That is super wrong (Sorry). Please reread the lesson and question\n" );
printf( "Try another option.\n\n" );
scanf( "%d", &sa1 );
}
else if( fa1 == 1 ) //If you chose the wrong answer
{
printf( "IIE. I'm sorry, but that was wrong. \"go\" is used to identify its a name\n" );
printf( "of a language, not the name of natinality. Try another option.\n\n" );
scanf( "%d", &sa1 );
}

else
{
return(0);
}

if( sa1 == 1 ) //If you didn't pay attention to me at all
{
printf( "IIE. I'm sorry, but that was wrong. \"go\" is used to identify its a name\n" );
printf( "of a language, not the name of natinality. The answer is 3.\n\n" );
scanf( "%d", &la1 );
}
else if( sa1 == 2 )
{
printf( "IIE. That is super wrong (Sorry). Please reread the lesson and question\n" );
printf( "the correct answer is 3.\n\n" );
scanf( "%d", &la1 );
}
else if( sa1 == 3 ) //If you were a good student :3
{
printf( "HAI! That is correct, dear friend. \"jin\" is the suffix for language.\n" );
printf( "Now, America in the japanese language is spelled \"Amerika\". Therefore,\n" );
printf( "you are an \"Amerikajin\". Isn't that awesome :D!? Rolls of the tongue!\n\n" );
printf( "But, you do not speak \"Amerikago\". In fact, just saying that makes\n" );
printf( "my biligual brain want kill it. No, you speak the language of England,\n" );
printf( "\"English\". Now in japanese, they just call english in an imformal\n" );
printf( "chat \"Eigo\" as opposed to \"Ingurandogo\" so as to not want to pull\n" );
printf( "the trigger XD!\n" );
printf( "MORE COMING SOON!!\n" );
}
else
{
return(0);
}

if( la1 == 3 )
{
printf( "HAI! That is correct, dear friend. \"jin\" is the suffix for language.\n" );
printf( "Now, America in the japanese language is spelled \"Amerika\". Therefore,\n" );
printf( "you are an \"Amerikajin\". Isn't that awesome :D!? Rolls of the tongue!\n\n" );
printf( "But, you do not speak \"Amerikago\". In fact, just saying that makes\n" );
printf( "my biligual brain want kill it. No, you speak the language of England,\n" );
printf( "\"English\". Now in japanese, they just call english in an imformal\n" );
printf( "chat \"Eigo\" as opposed to \"Ingurandogo\" so as to not want to pull\n" );
printf( "the trigger XD!\n" );
printf( "MORE COMING SOON!!\n" );
}
else
{
return(0);
}
return 0;
}
But the problem wasn't the b variable. It's the use of sa1 before it's assigned a value.

Tell me, if they answered correctly, what should sa1 be to guarantee the right message is printed. Is it really needed at all? We can go over a new designed later though. First you need to see that on line 72 sa1 might not have a value assigned to it yet (aka it contains garbage.)
sa1 is equal to 3 if you answered the question correctly :P. But at 72 the value is 1 I thought
sa1 is equal to 3 if you answered the question correctly
It should be, but it's not. Follow your code. fa1 == 3, but sa1 has not been assigned a value yet.

But at 72 the value is 1 I thought
No. sa1 value is being compared to 1, but it doesn't mean it is 1. If it is 1 then that if block will execute.
:P So how do I fix it? *Twirls her hair*
Again:
Mathhead200 wrote:
Unless I missed something, you did not give ["sa1"] a value before you read it in your if-statement; when they give a correct answer you should manually set it to a value of 3 (or whatever works for your code.)


*Types on his keyboard, and then clicks "Submit"*... For real, WTF up with all that extra? LOL :)
XDD I don't know I just am used to giving my physical motions and show emotion. Anyhow, sorry to be all girly X3. I think what you're pointing at is I need to give the variables values. But I don't know what values
Well in this case 3 seems to be the default "answered correctly" value. 3 should work. You already reset it to 1 or 2 in the respective else-if statements.

If you think that sounds weird (and you well after you get better at this) a (slightly) better solution is to set sa1 = fa1 after the first if else-if chain. Then you can avoid all though other statements.

(No need to apologize. I just think it's funny. You don't see those kind of posts much on programing forums. I don't think it's against the rules.)
Last edited on
Pages: 123