Trouble Shoot C++ From Zero Part 1

|









After I wrote about Learning C++ from Zero Part 1 Now I will share you about how to trouble shoot C++,

Algorithm:
-Initialization
HotCoffeeMilk <- 0
Cup <- 1
Spoon <- 1
MilkPowder <- 1
Sugar <- 1
HotWater <- 1
-Process
Cup <- Cup + MilkPowder
Cup <- Cup + Sugar
Cup <- Cup + HotWater
Cup <- Cup + HotWater
While Sugar = 1, Coffee = 1, HotWater = 1 and MilkPowder = 1 do
Cup <- Cup + Spoon
if Cup = 30 then
Sugar <- 0
Coffee <- 0
MilkPowder <- 0
{end if}
{end while}
-Finalization
HotCoffeeMilk <- 1
{end procedure}

The Codes,















The Problems,







Trouble shoots steps:
1. See error messages
2. Focus to a specific error line, try to understand error messages
3. Do analytics thinking, what fix should be?
4. Go to another line and fix it
5. After all lines checked and fixed, run program again with "gcc Trouble_Coffee_p1.cpp"
- If still see error messages, see detail whole codes from start to end, do integral thinking (compare structures with algorithm),
Then go to no 2 - 4 again
- If you still don't know how fix should be? , search online about anything related to error messages.
- If you're stuck don't know what to do, ask c++ forums
6. Finish, nothing error messages appear

See Problems (error messages) then go to spesific line:
-33:9 & 33:2: warning: missing terminating " character
this is line 33 -> printf("HotCoffeeMilk already to drink... yummy!! \");
33:2 -> no problems @ printf("
33:9 -> missing n after \
it should be, printf("HotCoffeeMilk already to drink... yummy!! \n");

Go to another line and fix it:
-7:2: error: expected ',' or ';' before 'int',
this is line 7 -> int Spoon = 1; and this is before int (line 6) -> int Cup = 1
missing ; after 1
it should be, int Cup = 1;

-12:8, 15:9, 17:8, 19:8, 21:8 expected constructor, destructor, or type conversion before '(' token
12:8, printf("Cup, Spoon, Coffee, MilkPowder, already exist \n");
12:8, nothing wrong here
15:9, prinntf("Cup added with MilkPowder \n");
15:9, wrong syntax @ prinntf, it should be printf
17:8, printf("Cup added with Coffee \n");
17:8, nothing wrong here
19:8, printf("Cup added with Sugar \n");
19:8, nothing wrong here
21:8, printf("Cup added with HotWater \n");
21:8, nothing wrong here

-14:2, 16:2, 18:2, 20:2 error: 'Cup' does not name a type
14:2, Cup = Cup + MilkPowder;
14:2, nothing wrong here
16:2, Cup = Cup + Coffee;
16:2, nothing wrong here
20:2, Cup =Cup + HotWater;
20:2, missing <space> after =, it should be Cup = Cup + HotWater;

-22:2: error: expected unqualified-id before 'while'
22:2, while ((Sugar == 1) && (Coffee == 1 && (MilkPowder == 1) && (HotWater == 1)) {
22:2, missing ) at (Coffee == 1, it should be (Coffee == 1)
Search before 'while' ,
-in at in main () [line 3] should be int

After all lines checked and fixed, run program again with "gcc Trouble_Coffee_p1.cpp"








wow... as You can see, error messages still appear, like I said before, see whole codes from start to end,
There is nothing wrong if we compare the codes with algorithm,
last error said, expected unqualified-id before 'while' that is the key.
it must be something wrong before while,
hey... see structures (tree), the integer main should be as 1st tree, and others as sub tree.
in notepad ++, before int main should be a tree [-], it must me something wrong before int main [3:1]
focused at /* This is Coffee MilkPowder Program *, there was a comment that missing / to terminate comment.
it should be /* This is Coffee MilkPowder Program */
congrats, now structures are correct.

run program again with "gcc Trouble_Coffee_p1.cpp"
we still see 2 error messages:





This code is mean expected '}' for terminate int main, but '}' already added for end procedure [35:1].
see the lines before, focused at '}' only.
binggo... there is expected '}' to terminate if [29:1]
[29:1], } /* end if */


run program again with "gcc Trouble_Coffee_p1.cpp"







Finish... nothing error messages appear

The right codes:
















Conclusion:
-read carefully error messages, sometimes there is no explain about specific line that cause an error.
e.g.: see [29:1] , no error messages for this line
-always think out of the box, if you think already fix all of errors but in fact error still exist
-Programmer jobs is not only how to make an efficient codes, right? but how to trouble shoot codes issues...

2 comments:

rachmat said...

In reality jobs you must deal with complicated trouble shoot situations , the real challenges are You must quickly as possible to solve this problems at situations:
-high under pressure,
Too many task to load, no friends help U, tight project time,
The manager said you’re stupid, U feels this is the worst project ever.
-bad customers
I don't wanna know this shit!!, Next week You must accomplish this to all branch with no error

My experiences, sometimes I success to solve the problems at right time but sometimes I fail

Unknown said...

udah ga minat kak jadi programmer, haha...
gara2 nonton film steve jobs

Post a Comment

leave comment here, thanks for visiting
[Friends Link] [Facebook] [Twitter]