LazerKittenz's Profile User Rating: -----

Reputation: 10 Tradesman
Group:
Contributors
Active Posts:
33 (0.02 per day)
Joined:
29-December 10
Profile Views:
3,063
Last Active:
User is offline Mar 09 2015 11:43 PM
Currently:
Offline

Previous Fields

Dream Kudos:
100
Icon   LazerKittenz has not set their status

Posts I've Made

  1. In Topic: SMTP Interfacing Application Various Problems

    Posted 1 Mar 2015

    View PostCurtis Rutland, on 26 February 2015 - 09:00 AM, said:

    As andrewsw mentioned, your problem is here:

                    showMenu();
                    if (showMenu() == 1)
                    {
                        enterEmail();
                    }
                    else if (showMenu() == 2)
                    {
                        userWantsToExit = true;
                    }
                    else if (showMenu() == 3)
                    {
                        checkMail();
                    }
                    else if (showMenu() == 4)
                    {
    
                    }
    


    showMenu() returns an integer, right? It also shows a menu. This is what we call a "side effect". It essentially means that the method does two things, one not necessarily related to the value that it returns.

    It means that every time you call showMenu, you'll display the menu.

    Initially, you call showMenu() but you don't capture the returned value! You completely ignore the returned value.

    Then your if-chain? Every if statement calls showMenu(). That means each time it gets into one of your if statements, it's going to show the menu again.

    So, rather than re-call the showMenu() over and over again, store the result from the showMenu call, and check that in your if statements.


    Thanks for laying this out for me! That makes sense.

    Quote

    That code still has the same problem that I pointed out in my previous post.


    Re-reading your post I now understand what you were saying. Sorry for being too simple to realize it. Thanks again for all of the help, both of you!
  2. In Topic: SMTP Interfacing Application Various Problems

    Posted 26 Feb 2015

    Hey, just thought I'd return and give a bit of an update.

    The code now runs properly, but the menu still does not loop correctly. My cousin said she would ask her professor about it and figure it out on her own, but I was interested in knowing the reason behind this.

    Updated Program.cs:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace GmailClient
    {
        class Program
        {
            static String emailAddress = "";
            static String emailPassword = "";
            static int selection = 0;
            static bool isLoggedIn;
            static bool userWantsToExit;
            static String[] checkedEmails;
    
            static void Main(string[] args)
            {
                Console.Title = "G-Mail Interface Client";
                while (!userWantsToExit)
                {
                    loggedIn();
                    showMenu();
                    if (showMenu() == 1)
                    {
                        enterEmail();
                    }
                    else if (showMenu() == 2)
                    {
                        userWantsToExit = true;
                    }
                    else if (showMenu() == 3)
                    {
                        checkMail();
                    }
                    else if (showMenu() == 4)
                    {
    
                    }
                    else
                    {
                        Console.WriteLine("Invalid selection");
                    }
                }
    
            }
    
            static void checkMail()
            {
                if (isLoggedIn == true)
                {
                    checkedEmails = Gmail.getMail(emailAddress, emailPassword);
                    foreach (string email in checkedEmails)
                    {
                        Console.WriteLine(email);
                    }
                }
                else
                {
                    Console.WriteLine("Please log-in!");
                }
            }
    
            static void sendMail()
            {
                String emailSubject;
                String emailBody;
                String emailRecipient;
                if (isLoggedIn == true)
                {
    
                    Console.Write("Enter recipient's e-mail: ");
                    emailRecipient = Console.ReadLine();
                    Console.Write("Enter e-mail of subject: ");
                    emailSubject = Console.ReadLine();
                    Console.WriteLine("Enter body of e-mail: ");
                    emailBody = Console.ReadLine();
    
                    Gmail.sendMail(emailAddress, emailPassword, emailRecipient, emailSubject, emailBody);
                }
                else
                {
                    Console.WriteLine("Please enter G-Mail credentials!");
                }
    
    
            }
    
            static void enterEmail()
            {
                Console.Write("E-Mail Address: ");
                emailAddress = Console.ReadLine();
                Console.Write("E-Mail Password: ");
                emailPassword = Console.ReadLine();
            }
    
            static Boolean loggedIn()
            {
                if (emailAddress == "" || emailPassword == "")
                {
                    isLoggedIn = false;
                    return false;
                }
                else
                {
                    isLoggedIn = true;
                    return true;
                }
            }
    
            static int showMenu()
            {
                if (isLoggedIn == false)
                {
                    Console.WriteLine("_____MENU_____");
                    Console.WriteLine("1. Enter G-Mail Credentials");
                    Console.WriteLine("2. Exit Application");
                    Console.Write("What would you like to do? ");
                    selection = Convert.ToInt32(Console.ReadLine());
                    return selection;
                }
                else if (isLoggedIn == true)
                {
                    Console.WriteLine("_____MENU_____");
                    Console.WriteLine("1. Change G-Mail Credentials");
                    Console.WriteLine("2. Exit Application");
                    Console.WriteLine("3. Check Mail");
                    Console.WriteLine("4. Send Mail");
                    Console.Write("What would you like to do? ");
                    selection = Convert.ToInt32(Console.ReadLine());
                    return selection;
                }
                else
                {
                    return 0;
                }
    
            }
        }
    }
    
    
  3. In Topic: SMTP Interfacing Application Various Problems

    Posted 24 Feb 2015

    I was trying to work it out on my own before I try and lay out the methodology behind it.

    Once I get home from work I will try again using a dedicated variable to store it.

    Another thing I forgot to add: would it be better to do the showMenu() method as I did in the first bit of code where I seperated the loggedIn() true and loggedIn() false showMenu() methods. So the if statement would be in the Main method instead of in the showMenu() method?

    I'll most likely be back!

    Thanks,
    Andrew

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

Comments

LazerKittenz has no profile comments yet. Why not say hello?