Ugh... what am I doing WRONG!

Pages: 123
*Giggles and blushes* I'm kind of one of those programmers that likes to have tons of fun while programming. Anyhow, what does [tt] do?
*Flinches visibly at egrarious use of scanf and prinf*

In C++, we tend towards cin and cout, which are part of the iostream library.
Sorry, the [tt] was for posting formatting. I edited it.

+1 Moschops
But I would get the program working first, then change your C to C++
Ugh, I feel like a dumb wench
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 = 3; //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( sa1 = fa1 )
{
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;
}

It's still breaking
1
2
3
4
5
6
...
int e;
int fa1;
int sa1 = 3;
int la1 = 3;
...
Oh :3 cool!!
Does that mean you figured it out?
Not quite. I'm a slow learner. You have to explain everything because I hate to assume.
Sorry
Look at this sample program:
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
#include <iostream>

using namespace std;

int main() {
    int x, y; //create two integers x and y

    cin >> x; //read a value into x from standard input

    //do something based on the x value
    if( x > 0 ) {
        cout << "x is a positive number\n";
    } else if( x < 0 ) {
        cout << "x is a negative number\n>";
        cin >> y; //read a value into y from standard input
    } else {
        cout << "x is zero\n";
        return 0;
    }

    //do something based on the y value
    if( y % 2 == 0 ) {
        cout << "y is an even number\n";
    } else {
        cout << "y is an odd number\n";
    }

    return 0;
}

Now, on line 22 we have a problem. y might not have been given a value yet, but we're still trying to read its value. y would only have a value (given by the user's input) if x < 0; but if x > 0, y contains garbage data. This leads to unpredictable behavior. This is exactly the same problem you had in your program. You could try running this program to see what I'm saying. You could also fix it and see how it works predictably.

Read each line of your program to yourself (carefully.) Comment each section (or even each line) with what it's doing. This might help you understand the program better.
So are you saying I shouldn't make answering with 1 or 2 go to a middle man solution because it causes rubbish data? I think it's starting to make since. Like, are you saying I should make answering with 1 or 2 lead to a solution of it's own *rubs her forehead* I'm sure I'm over thinking this.
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
#include "stdafx.h"

int _tmain(int argc, TCHAR* argv[])
{
int e; //First varible
int a1 = 3; //Answer 1
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", &a1 );
}
else
{
return (0);
}

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

else if( a1 - 1 ) //If you didn't pay attention to me at all.
{
printf( "IIE. That is super wrong (Sorry). \"Go\" is used to identify it's a name\n" );
printf( "of a language, not the name of natinality.  \"jin\" is the suffix you'd\n" );
printf( "use to say \"of (the country)\". But don't worry, you'll get better at\n\n" );
printf( "this :3./");
printf( "Now, America in the japanese language is spelled \"Amerika\".\n" );
printf( "Therefore, you are an \"Amerikajin\". Isn't that awesome :D!? Rolls off\n\n" );
printf( "the tongue! But, you do not speak \"Amerikago\". In fact, just saying\n" );
printf( "that makes my biligual brain want kill it. No, you speak the language\n" );
printf( "of England, \"English\". Now, in japanese they just call english in an\n" );
printf( "informal chat \"Eigo\" as opposed to \"Ingurandogo\" so as to not want\n" );
printf( "to pull the trigger XD!\n" );
printf( "MORE COMING SOON!!\n" );
scanf( "%d", &a1 );
}
else if( a1 - 2 ) //If you chose the wrong answer.
{
printf( "IIE. I'm sorry, but you messed up. \"Go\" is used to identify its a name\n" );
printf( "of a language, not the name of natinality.  \"jin\" is the suffix you'd\n" );
printf( "use to say \"language of\". But don't worry, you'll get better at this :3\n\n" );
printf( "Now, America in the japanese language is spelled \"Amerika\".\n" );
printf( "Therefore, you are an \"Amerikajin\". Isn't that awesome :D!? Rolls off\n\n" );
printf( "the tongue! But, you do not speak \"Amerikago\". In fact, just saying\n" );
printf( "that makes my biligual brain want kill it. No, you speak the language\n" );
printf( "of England, \"English\". Now, in japanese they just call english in an\n" );
printf( "informal chat \"Eigo\" as opposed to \"Ingurandogo\" so as to not want\n" );
printf( "to pull the trigger XD!\n" );
printf( "MORE COMING SOON!!\n" );
}
else
{
return(0);
}
scanf ( "%d", &b );
if( b )
{
	return(0);
}
return 0;
}

Before you ask, I added the scanf ( "%d" ); because that's the only way the last message would show XP
Last edited on
if( fa1 )

if will examine the contents of the brackets; in the event that the contents of the brackets evaluates to false (or zero), then the following code will not be executed, and if the contents of the brackets evaluates to true (or anything that isn't zero), the following code will be executed.

So, what does ( fa1 ) evaluate to? It evaluates to fa1. I suspect you meant something along the lines of

if( fa1==3)

In this case, the contents of the brackets are ( fa1==3) which tests the values of fa1.

It's a really, really big difference.
Last edited on
What a second XP So do I put a value on int fa1 or not?
What a second XP So do I put a value on int fa1 or not?


Depends what you want to do with it. If you can tell me what you want to do with it, you'll already know the answer to your question.
Okay, I reviewed my code and have fixed to so it's more efficient *Giggles* You can look at the last bit of code I posted here and judge for yourself.
else if( a1 - 1 )

I see what you've tried to do there. I think. You're trying to directly use the fact that zero will evaluate to false, and non-zero to true. You can code like that, but it's very bad form for lots of reasons.

You'd have a much easier time of things if you stuck to the common relational operators. Here's the code again, with lots removed to make it clear.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
if( a1 == 3 ) //I love you, you're an amazing student.
{
printf( "HAI! That is correct, dear friend. \"jin\" is the suffix for nationality.\n" );
}
else if( a1 == 2 ) //If you didn't pay attention to me at all.
{
printf( "IIE. That is super wrong (Sorry). \"Go\" is used to identify it's a name\n" );
}
else if( a1 == 1 ) //If you chose the wrong answer.
{
printf( "IIE. I'm sorry, but you messed up. \"Go\" is used to identify its a name\n" );
}
else
{
return(0);
}
Okay. I fixed it again doing as you suggested. It seems to be doing exactly what it did before so thank for your suggestion nWn I can understand what you meant by this way will be easier. I think my program will be working brilliantly. But we end up back to the question of "how do you make it so the last
1
2
3
4
5
scanf ( "%d", &b );
if( b )
{
	return(0);
}
isn't required to make the program function?"
Last edited on
In what way does it not function without that there?
If it isn't there then after you enter your answer for what a1 is it will flash the solution and then the window will close. so let's say you tell the program a1 is 2... then the paragraph that's supposed to appear for 2 will flash and the window closes.
Pages: 123