Jump to content

Okay guys. I am in need of assistance. I am currently in college for software development and I'm doing this assignment where I need to demonstrate control structures and loops using C#. This is for an advanced programming class. It's basically the same program I wrote when I was learning C++. I'm basically just porting it over. Everything about the program works perfectly fine and as it should EXCEPT for my option B choice. It's a sentinel controlled do..while loop that takes numbers from the user and then they input -999 to exit the loop and output their smallest value. For SOME reason I can't for the life of me get it to register the smallest number. It just outputs the smallest number as being 0 EVERY time UNLESS the user enters a negative number. I don't understand. When I wrote this same program in c++ it worked perfectly. I know obviously the syntax is different but maybe I have tunnel vision right now because I don't see any issue with my algorithm. I'd appreciate some help here. Here's my code. I've made the code that I THINK is causing the issue in bold. I'm also putting a screenshot of the console on here



//Programmed by Ryan C. Jones
//C# Control structures assignment
//week 2
//August 14th 2015
//Instructor: Diesch
 
using System;//using system
 
class ControlStructures//control structures class
{
    static void Main()//static non value returning main
    {
        //Declarations
        double largeNum      = 0;//integer for large number
        double tempNum       = 0;//integer for temp number
        string tempNumStr;//string for temp number input
        double smallNum      = 0;//integer for small number
        double counter       = 0;//integer for counter
        string counterStr;//string for counter
        double tempCounter   = 0;//integer for temp counter to allow for decremental for loop. (I like this code a lot it's neat and necessary otherwise the count would be decremented with each new number which we don't want)
        string tempCounterStr;//string for temp counter input
        string letterChoice;//string for letter choice
        const int HYPHENS = 80;//constant int for hyphen for loop
        const double STOP    = -999;//constant int for stopping input
        bool leave        = false;//boolean for leaving
        string wlcmMsg    = "-Algorithms, Concept, and Code by Ryan C. Jones-\n\nWelcome to my menu program! You may choose from 3 options.\n\n";//welcome message string
        //end declarations
        //begin i/o
        Console.WriteLine("{0}", wlcmMsg);//output welcome message
        while (!leave)//while loop for boolean leave (option C)
        {
            for (int i = 0; i < HYPHENS; i++)//for loop for the hyphens (instead of outputting 80 hyphens)
            {
                Console.Write("-");//output 80 hyphens 
            }//end of first for loop
            //spacing for readability
            Console.WriteLine();//next line
            Console.WriteLine("                                  Menu");//output menu
            Console.WriteLine("Option A)Calculate the largest number from a known quantity of numbers.\n\nOption B)Calculate the smallest number from an unknown quantity of numbers.\n\nOption C)Exit the program.\n\n");//output menu options
            //spacing for readability
            for (int i = 0; i < HYPHENS; i++)//for loop for bottom hyphens
            {
                Console.Write("-");//output 80 hyphens
            }//end of second for loop
            //spacing for readability
            Console.WriteLine();//add another space after menu for readability
            letterChoice = Console.ReadLine();//set letter choice to take input
            //logical checks for A
            if (letterChoice == "A" || letterChoice == "a")//if letter choice is equivalent to A or a
            {
                Console.WriteLine("\nHow many numbers would you like to [ENTER]?: ");//output question to user
                counterStr = Console.ReadLine();//take input in the form of a string
                counter = Convert.ToInt32(counterStr);//convert the input string to an int so it can be manipulated below
                tempCounter = Convert.ToInt32(counterStr);//convert temp counter to an int so it can be manipulated below
                //spacing for readability
                for (int i = 0; i < counter; i++)//for loop to decrement temp counter by 1 with each new number
                {
                    Console.WriteLine("Please [ENTER] {0} more: ", tempCounter--);//this code is pretty self explanatory. decrement temp counter by 1 with each new number.
                    tempNumStr = Console.ReadLine();//same principle as before take input in the form of a string
                    tempNum = Convert.ToInt32(tempNumStr);//and convert it to an int to be manipulated
                    //spacing for readability
                    if (tempNum > largeNum)//if temp num is greater than large num
                    {
                        largeNum = tempNum;//large num is set to temp num
                    }
                    //spacing for readability
                }//end of decremental for loop
                //spacing for readability
                Console.WriteLine("The Largest value you input was {0}", largeNum);//output largest number
            }//end of a option
            //end logical checks for A
            //logical checks for B
            if (letterChoice == "B" || letterChoice == "b")//if letter choice is equivalent to B or b
            {
                Console.WriteLine("\nPlease [ENTER] as many numbers as you like (to stop input [ENTER] {0})", STOP);//output instructions to user
                //spacing for readability
                do// do the following code block while input is not equating to STOP (as demonstrated below)
                {
                    Console.Write("Please [ENTER] a number: ");//output asking for a number
                    tempNumStr = Console.ReadLine();//samee principle as before get input in a string
                    tempNum = Convert.ToInt32(tempNumStr);//convert the string to an int for manipulation
                    //spacing for readability
                    if (smallNum > tempNum && tempNum != STOP)//if small number is less than temp number and temp number is NOT equavalent to const STOP variable (-999)
                    {
                        smallNum = tempNum;//small number is set to temp number
                    }
                }//end of do..while code block
                while (tempNum != STOP);//end of do..while for input not equating to -999 (STOP) (as demonstrated above)
                //spacing for readability
                Console.WriteLine("\nThe smallest value you input was: {0}", smallNum);//output smallest number
            }//end of option B
            //end logical checks for B
            //logical checks for C
            if (letterChoice == "C" || letterChoice == "c")//If letter choice is equivalent to C or c
            {
                Console.WriteLine("\nThanks for trying my menu program! Have a great day!(Press any key)");//output to user to say goodbye
                Console.ReadLine();//hold the console open so user can read aforementioned goodbye
                leave = true;//set leave to equal true to end the program
            }
            //end logical checks for C
        }//end of while loop for menu
    }//end of static non value returning main
}//end of control structures class
//end of program

Link to comment
https://linustechtips.com/topic/430430-simple-c-program-help/
Share on other sites

Link to post
Share on other sites

Console.WriteLine("Use Code Tags");Console.ReadKey();

I'll run the code in visual studio and see if I can identify the problem

Speedtests

WiFi - 7ms, 22Mb down, 10Mb up

Ethernet - 6ms, 47.5Mb down, 9.7Mb up

 

Rigs

Spoiler

 Type            Desktop

 OS              Windows 10 Pro

 CPU             i5-4430S

 RAM             8GB CORSAIR XMS3 (2x4gb)

 Cooler          LC Power LC-CC-97 65W

 Motherboard     ASUS H81M-PLUS

 GPU             GeForce GTX 1060

 Storage         120GB Sandisk SSD (boot), 750GB Seagate 2.5" (storage), 500GB Seagate 2.5" SSHD (cache)

 

Spoiler

Type            Server

OS              Ubuntu 14.04 LTS

CPU             Core 2 Duo E6320

RAM             2GB Non-ECC

Motherboard     ASUS P5VD2-MX SE

Storage         RAID 1: 250GB WD Blue and Seagate Barracuda

Uses            Webserver, NAS, Mediaserver, Database Server

 

Quotes of Fame

On 8/27/2015 at 10:09 AM, Drixen said:

Linus is light years ahead a lot of other YouTubers, he isn't just an average YouTuber.. he's legitimately, legit.

On 10/11/2015 at 11:36 AM, Geralt said:

When something is worth doing, it's worth overdoing.

On 6/22/2016 at 10:05 AM, trag1c said:

It's completely blown out of proportion. Also if you're the least bit worried about data gathering then you should go live in a cave a 1000Km from the nearest establishment simply because every device and every entity gathers information these days. In the current era privacy is just fallacy and nothing more.

 

Link to comment
https://linustechtips.com/topic/430430-simple-c-program-help/#findComment-5772142
Share on other sites

Link to post
Share on other sites

Console.WriteLine("Use Code Tags");Console.ReadKey();

I'll run the code in visual studio and see if I can identify the problem

 

There are no syntax errors. It's a logical error. I fuck I am just Stuck as hell. I don't usually have such problems with such simple logic.

Link to comment
https://linustechtips.com/topic/430430-simple-c-program-help/#findComment-5772165
Share on other sites

Link to post
Share on other sites

Thank you. Much appreciated.

 

From what I can see, it looks like because SmallNum is already zero, and every number above zero is bigger than it, it's not changing

 

OwhZJ9D.png

Speedtests

WiFi - 7ms, 22Mb down, 10Mb up

Ethernet - 6ms, 47.5Mb down, 9.7Mb up

 

Rigs

Spoiler

 Type            Desktop

 OS              Windows 10 Pro

 CPU             i5-4430S

 RAM             8GB CORSAIR XMS3 (2x4gb)

 Cooler          LC Power LC-CC-97 65W

 Motherboard     ASUS H81M-PLUS

 GPU             GeForce GTX 1060

 Storage         120GB Sandisk SSD (boot), 750GB Seagate 2.5" (storage), 500GB Seagate 2.5" SSHD (cache)

 

Spoiler

Type            Server

OS              Ubuntu 14.04 LTS

CPU             Core 2 Duo E6320

RAM             2GB Non-ECC

Motherboard     ASUS P5VD2-MX SE

Storage         RAID 1: 250GB WD Blue and Seagate Barracuda

Uses            Webserver, NAS, Mediaserver, Database Server

 

Quotes of Fame

On 8/27/2015 at 10:09 AM, Drixen said:

Linus is light years ahead a lot of other YouTubers, he isn't just an average YouTuber.. he's legitimately, legit.

On 10/11/2015 at 11:36 AM, Geralt said:

When something is worth doing, it's worth overdoing.

On 6/22/2016 at 10:05 AM, trag1c said:

It's completely blown out of proportion. Also if you're the least bit worried about data gathering then you should go live in a cave a 1000Km from the nearest establishment simply because every device and every entity gathers information these days. In the current era privacy is just fallacy and nothing more.

 

Link to comment
https://linustechtips.com/topic/430430-simple-c-program-help/#findComment-5772169
Share on other sites

Link to post
Share on other sites

See? It's eluding me. Also. Nice windows 10 biggrin.png I got windows 10 too biggrin.png yay windows 10 club biggrin.png

 

I think I managed to fix it, probably in the most dodgy way. At the top where the variables are declared, I set smallNum to a number that the user is very unlikely to enter

double smallNum = 999.9654;//integer for small number

Then further down where the code checks to see if tempNum is smaller than smallNum, it checks to see if smallNum is equal to the unique value

if ((smallNum == 999.9654 || smallNum > tempNum) && tempNum != STOP)//if small number is less than temp number and temp number is NOT equavalent to const STOP variable (-999){     smallNum = tempNum;//small number is set to temp number}

 

I didn't change the comments though, you might need to change them to show what the code is doing and why the smallNum variable isn't zero ^_^

class ControlStructures//control structures class{    static void Main()//static non value returning main    {        //Declarations        double largeNum = 0;//integer for large number        double tempNum = 0;//integer for temp number        string tempNumStr;//string for temp number input        double smallNum = 999.9654;//integer for small number        double counter = 0;//integer for counter        string counterStr;//string for counter        double tempCounter = 0;//integer for temp counter to allow for decremental for loop. (I like this code a lot it's neat and necessary otherwise the count would be decremented with each new number which we don't want)        string tempCounterStr;//string for temp counter input        string letterChoice;//string for letter choice        const int HYPHENS = 80;//constant int for hyphen for loop        const double STOP = -999;//constant int for stopping input        bool leave = false;//boolean for leaving        string wlcmMsg = "-Algorithms, Concept, and Code by Ryan C. Jones-\n\nWelcome to my menu program! You may choose from 3 options.\n\n";//welcome message string        //end declarations        //begin i/o        Console.WriteLine("{0}", wlcmMsg);//output welcome message        while (!leave)//while loop for boolean leave (option C)        {            for (int i = 0; i < HYPHENS; i++)//for loop for the hyphens (instead of outputting 80 hyphens)            {                Console.Write("-");//output 80 hyphens             }//end of first for loop            //spacing for readability            Console.WriteLine();//next line            Console.WriteLine("                                  Menu");//output menu            Console.WriteLine("Option A)Calculate the largest number from a known quantity of numbers.\n\nOption B)Calculate the smallest number from an unknown quantity of numbers.\n\nOption C)Exit the program.\n\n");//output menu options            //spacing for readability            for (int i = 0; i < HYPHENS; i++)//for loop for bottom hyphens            {                Console.Write("-");//output 80 hyphens            }//end of second for loop            //spacing for readability            Console.WriteLine();//add another space after menu for readability            letterChoice = Console.ReadLine();//set letter choice to take input            //logical checks for A            if (letterChoice == "A" || letterChoice == "a")//if letter choice is equivalent to A or a            {                Console.WriteLine("\nHow many numbers would you like to [ENTER]?: ");//output question to user                counterStr = Console.ReadLine();//take input in the form of a string                counter = Convert.ToInt32(counterStr);//convert the input string to an int so it can be manipulated below                tempCounter = Convert.ToInt32(counterStr);//convert temp counter to an int so it can be manipulated below                //spacing for readability                for (int i = 0; i < counter; i++)//for loop to decrement temp counter by 1 with each new number                {                    Console.WriteLine("Please [ENTER] {0} more: ", tempCounter--);//this code is pretty self explanatory. decrement temp counter by 1 with each new number.                    tempNumStr = Console.ReadLine();//same principle as before take input in the form of a string                    tempNum = Convert.ToInt32(tempNumStr);//and convert it to an int to be manipulated                    //spacing for readability                    if (tempNum > largeNum)//if temp num is greater than large num                    {                        largeNum = tempNum;//large num is set to temp num                    }                    //spacing for readability                }//end of decremental for loop                //spacing for readability                Console.WriteLine("The Largest value you input was {0}", largeNum);//output largest number            }//end of a option            //end logical checks for A            //logical checks for B            if (letterChoice == "B" || letterChoice == "b")//if letter choice is equivalent to B or b            {                Console.WriteLine("\nPlease [ENTER] as many numbers as you like (to stop input [ENTER] {0}", STOP);//output instructions to user                //spacing for readability                do// do the following code block while input is not equating to STOP (as demonstrated below)                {                    Console.Write("Please [ENTER] a number: ");//output asking for a number                    tempNumStr = Console.ReadLine();//samee principle as before get input in a string                    tempNum = Convert.ToInt32(tempNumStr);//convert the string to an int for manipulation                    //spacing for readability                    if ((smallNum == 999.9654 || smallNum > tempNum) && tempNum != STOP)//if small number is less than temp number and temp number is NOT equavalent to const STOP variable (-999)                    {                        smallNum = tempNum;//small number is set to temp number                    }                }//end of do..while code block                while (tempNum != STOP);//end of do..while for input not equating to -999 (STOP) (as demonstrated above)                //spacing for readability                Console.WriteLine("\nThe smallest value you input was: {0}", smallNum);//output smallest number            }//end of option B            //end logical checks for B            //logical checks for C            if (letterChoice == "C" || letterChoice == "c")//If letter choice is equivalent to C or c            {                Console.WriteLine("\nThanks for trying my menu program! Have a great day!(Press any key)");//output to user to say goodbye                Console.ReadLine();//hold the console open so user can read aforementioned goodbye                leave = true;//set leave to equal true to end the program            }            //end logical checks for C        }//end of while loop for menu    }//end of static non value returning main}//end of control structures class//end of program

Speedtests

WiFi - 7ms, 22Mb down, 10Mb up

Ethernet - 6ms, 47.5Mb down, 9.7Mb up

 

Rigs

Spoiler

 Type            Desktop

 OS              Windows 10 Pro

 CPU             i5-4430S

 RAM             8GB CORSAIR XMS3 (2x4gb)

 Cooler          LC Power LC-CC-97 65W

 Motherboard     ASUS H81M-PLUS

 GPU             GeForce GTX 1060

 Storage         120GB Sandisk SSD (boot), 750GB Seagate 2.5" (storage), 500GB Seagate 2.5" SSHD (cache)

 

Spoiler

Type            Server

OS              Ubuntu 14.04 LTS

CPU             Core 2 Duo E6320

RAM             2GB Non-ECC

Motherboard     ASUS P5VD2-MX SE

Storage         RAID 1: 250GB WD Blue and Seagate Barracuda

Uses            Webserver, NAS, Mediaserver, Database Server

 

Quotes of Fame

On 8/27/2015 at 10:09 AM, Drixen said:

Linus is light years ahead a lot of other YouTubers, he isn't just an average YouTuber.. he's legitimately, legit.

On 10/11/2015 at 11:36 AM, Geralt said:

When something is worth doing, it's worth overdoing.

On 6/22/2016 at 10:05 AM, trag1c said:

It's completely blown out of proportion. Also if you're the least bit worried about data gathering then you should go live in a cave a 1000Km from the nearest establishment simply because every device and every entity gathers information these days. In the current era privacy is just fallacy and nothing more.

 

Link to comment
https://linustechtips.com/topic/430430-simple-c-program-help/#findComment-5772219
Share on other sites

Link to post
Share on other sites

I think I managed to fix it, probably in the most dodgy way. At the top where the variables are declared, I set smallNum to a number that the user is very unlikely to enter

double smallNum = 999.9654;//integer for small number

Then further down where the code checks to see if tempNum is smaller than smallNum, it checks to see if smallNum is equal to the unique value

if ((smallNum == 999.9654 || smallNum > tempNum) && tempNum != STOP)//if small number is less than temp number and temp number is NOT equavalent to const STOP variable (-999){     smallNum = tempNum;//small number is set to temp number}

 

I didn't change the comments though, you might need to change them to show what the code is doing and why the smallNum variable isn't zero ^_^

The only issue I can see with that is the assignment instructions. 

"To be sure you understand the concepts of control structures with C#, create a .NET console application that demonstrates C# structures displaying a menu with the following choices to the user:

A - Find the largest # with a known quantity of numbers

B - Find the smallest # with an unknown quantity of numbers

C - Quit

Please enter your choice ___

This menu needs to be repeatedly displayed until the user chooses to quit.

If A is chosen, you should ask the user how many numbers he wants to enter. If he enters 5, you should read 5 numbers from him. You should then display the largest number he entered. Use a loop to read the input, compare the values, and display the largest.

If B is chosen, you should keep reading numbers no matter what until the user enters -999. Then you should display the smallest number he entered not counting the -999.

"

class ControlStructures//control structures class{    static void Main()//static non value returning main    {        //Declarations        double largeNum = 0;//integer for large number        double tempNum = 0;//integer for temp number        string tempNumStr;//string for temp number input        double smallNum = 999.9654;//integer for small number        double counter = 0;//integer for counter        string counterStr;//string for counter        double tempCounter = 0;//integer for temp counter to allow for decremental for loop. (I like this code a lot it's neat and necessary otherwise the count would be decremented with each new number which we don't want)        string tempCounterStr;//string for temp counter input        string letterChoice;//string for letter choice        const int HYPHENS = 80;//constant int for hyphen for loop        const double STOP = -999;//constant int for stopping input        bool leave = false;//boolean for leaving        string wlcmMsg = "-Algorithms, Concept, and Code by Ryan C. Jones-\n\nWelcome to my menu program! You may choose from 3 options.\n\n";//welcome message string        //end declarations        //begin i/o        Console.WriteLine("{0}", wlcmMsg);//output welcome message        while (!leave)//while loop for boolean leave (option C)        {            for (int i = 0; i < HYPHENS; i++)//for loop for the hyphens (instead of outputting 80 hyphens)            {                Console.Write("-");//output 80 hyphens             }//end of first for loop            //spacing for readability            Console.WriteLine();//next line            Console.WriteLine("                                  Menu");//output menu            Console.WriteLine("Option A)Calculate the largest number from a known quantity of numbers.\n\nOption B)Calculate the smallest number from an unknown quantity of numbers.\n\nOption C)Exit the program.\n\n");//output menu options            //spacing for readability            for (int i = 0; i < HYPHENS; i++)//for loop for bottom hyphens            {                Console.Write("-");//output 80 hyphens            }//end of second for loop            //spacing for readability            Console.WriteLine();//add another space after menu for readability            letterChoice = Console.ReadLine();//set letter choice to take input            //logical checks for A            if (letterChoice == "A" || letterChoice == "a")//if letter choice is equivalent to A or a            {                Console.WriteLine("\nHow many numbers would you like to [ENTER]?: ");//output question to user                counterStr = Console.ReadLine();//take input in the form of a string                counter = Convert.ToInt32(counterStr);//convert the input string to an int so it can be manipulated below                tempCounter = Convert.ToInt32(counterStr);//convert temp counter to an int so it can be manipulated below                //spacing for readability                for (int i = 0; i < counter; i++)//for loop to decrement temp counter by 1 with each new number                {                    Console.WriteLine("Please [ENTER] {0} more: ", tempCounter--);//this code is pretty self explanatory. decrement temp counter by 1 with each new number.                    tempNumStr = Console.ReadLine();//same principle as before take input in the form of a string                    tempNum = Convert.ToInt32(tempNumStr);//and convert it to an int to be manipulated                    //spacing for readability                    if (tempNum > largeNum)//if temp num is greater than large num                    {                        largeNum = tempNum;//large num is set to temp num                    }                    //spacing for readability                }//end of decremental for loop                //spacing for readability                Console.WriteLine("The Largest value you input was {0}", largeNum);//output largest number            }//end of a option            //end logical checks for A            //logical checks for B            if (letterChoice == "B" || letterChoice == "b")//if letter choice is equivalent to B or b            {                Console.WriteLine("\nPlease [ENTER] as many numbers as you like (to stop input [ENTER] {0}", STOP);//output instructions to user                //spacing for readability                do// do the following code block while input is not equating to STOP (as demonstrated below)                {                    Console.Write("Please [ENTER] a number: ");//output asking for a number                    tempNumStr = Console.ReadLine();//samee principle as before get input in a string                    tempNum = Convert.ToInt32(tempNumStr);//convert the string to an int for manipulation                    //spacing for readability                    if ((smallNum == 999.9654 || smallNum > tempNum) && tempNum != STOP)//if small number is less than temp number and temp number is NOT equavalent to const STOP variable (-999)                    {                        smallNum = tempNum;//small number is set to temp number                    }                }//end of do..while code block                while (tempNum != STOP);//end of do..while for input not equating to -999 (STOP) (as demonstrated above)                //spacing for readability                Console.WriteLine("\nThe smallest value you input was: {0}", smallNum);//output smallest number            }//end of option B            //end logical checks for B            //logical checks for C            if (letterChoice == "C" || letterChoice == "c")//If letter choice is equivalent to C or c            {                Console.WriteLine("\nThanks for trying my menu program! Have a great day!(Press any key)");//output to user to say goodbye                Console.ReadLine();//hold the console open so user can read aforementioned goodbye                leave = true;//set leave to equal true to end the program            }            //end logical checks for C        }//end of while loop for menu    }//end of static non value returning main}//end of control structures class//end of program
Link to comment
https://linustechtips.com/topic/430430-simple-c-program-help/#findComment-5772238
Share on other sites

Link to post
Share on other sites

The only issue I can see with that is the assignment instructions. 

"To be sure you understand the concepts of control structures with C#, create a .NET console application that demonstrates C# structures displaying a menu with the following choices to the user:

A - Find the largest # with a known quantity of numbers

B - Find the smallest # with an unknown quantity of numbers

C - Quit

Please enter your choice ___

This menu needs to be repeatedly displayed until the user chooses to quit.

If A is chosen, you should ask the user how many numbers he wants to enter. If he enters 5, you should read 5 numbers from him. You should then display the largest number he entered. Use a loop to read the input, compare the values, and display the largest.

If B is chosen, you should keep reading numbers no matter what until the user enters -999. Then you should display the smallest number he entered not counting the -999.

"

 

Since -999 is the stop value, it might work better as the initial smallNum variable maybe?

Speedtests

WiFi - 7ms, 22Mb down, 10Mb up

Ethernet - 6ms, 47.5Mb down, 9.7Mb up

 

Rigs

Spoiler

 Type            Desktop

 OS              Windows 10 Pro

 CPU             i5-4430S

 RAM             8GB CORSAIR XMS3 (2x4gb)

 Cooler          LC Power LC-CC-97 65W

 Motherboard     ASUS H81M-PLUS

 GPU             GeForce GTX 1060

 Storage         120GB Sandisk SSD (boot), 750GB Seagate 2.5" (storage), 500GB Seagate 2.5" SSHD (cache)

 

Spoiler

Type            Server

OS              Ubuntu 14.04 LTS

CPU             Core 2 Duo E6320

RAM             2GB Non-ECC

Motherboard     ASUS P5VD2-MX SE

Storage         RAID 1: 250GB WD Blue and Seagate Barracuda

Uses            Webserver, NAS, Mediaserver, Database Server

 

Quotes of Fame

On 8/27/2015 at 10:09 AM, Drixen said:

Linus is light years ahead a lot of other YouTubers, he isn't just an average YouTuber.. he's legitimately, legit.

On 10/11/2015 at 11:36 AM, Geralt said:

When something is worth doing, it's worth overdoing.

On 6/22/2016 at 10:05 AM, trag1c said:

It's completely blown out of proportion. Also if you're the least bit worried about data gathering then you should go live in a cave a 1000Km from the nearest establishment simply because every device and every entity gathers information these days. In the current era privacy is just fallacy and nothing more.

 

Link to comment
https://linustechtips.com/topic/430430-simple-c-program-help/#findComment-5772249
Share on other sites

Link to post
Share on other sites

Since -999 is the stop value, it might work better as the initial smallNum variable maybe?

Yeah that didn't work. I'd have to change the whole option B to implement it that way. There's gotta be a simpler way to do it without altering the const variable because the do while loop depends on that.

Link to comment
https://linustechtips.com/topic/430430-simple-c-program-help/#findComment-5772283
Share on other sites

Link to post
Share on other sites

I figured it out. Thanks to you dude. Your logic that got me thinking of what would work was from before. When you set small number to equal a number that no one would ever enter. Well I just changed that to 0. Here's the updated code. 

 

//Programmed by Ryan C. Jones//C# Control structures assignment//week 2//August 14th 2015//Instructor: Diesch using System;//using system class ControlStructures//control structures class{    static void Main()//static non value returning main    {        //Declarations        double largeNum      = 0;//integer for large number        double tempNum       = 0;//integer for temp number        string tempNumStr;//string for temp number input        double smallNum      = 0;//integer for small number        double counter       = 0;//integer for counter        string counterStr;//string for counter        double tempCounter   = 0;//integer for temp counter to allow for decremental for loop. (I like this code a lot it's neat and necessary otherwise the count would be decremented with each new number which we don't want)        string tempCounterStr;//string for temp counter input        string letterChoice;//string for letter choice        const int HYPHENS = 80;//constant int for hyphen for loop        const double STOP    = -999;//constant int for stopping input        bool leave        = false;//boolean for leaving        string wlcmMsg    = "-Algorithms, Concept, and Code by Ryan C. Jones-\n\nWelcome to my menu program! You may choose from 3 options.\n\n";//welcome message string        //end declarations        //begin i/o        Console.WriteLine("{0}", wlcmMsg);//output welcome message        while (!leave)//while loop for boolean leave (option C)        {            for (int i = 0; i < HYPHENS; i++)//for loop for the hyphens (instead of outputting 80 hyphens)            {                Console.Write("-");//output 80 hyphens             }//end of first for loop            //spacing for readability            Console.WriteLine();//next line            Console.WriteLine("                                  Menu");//output menu            Console.WriteLine("Option A)Calculate the largest number from a known quantity of numbers.\n\nOption B)Calculate the smallest number from an unknown quantity of numbers.\n\nOption C)Exit the program.\n\n");//output menu options            //spacing for readability            for (int i = 0; i < HYPHENS; i++)//for loop for bottom hyphens            {                Console.Write("-");//output 80 hyphens            }//end of second for loop            //spacing for readability            Console.Write("Please make a choice <A, B, C> (you may use lowercase letters): ");//ask user their choice            letterChoice = Console.ReadLine();//set letter choice to take input            Console.WriteLine();//add another line for readability            //logical checks for A            if (letterChoice == "A" || letterChoice == "a")//if letter choice is equivalent to A or a            {                Console.Write("How many numbers would you like to [ENTER]?: ");//output question to user                counterStr = Console.ReadLine();//take input in the form of a string                Console.WriteLine();//add another line for readability                counter = Convert.ToInt32(counterStr);//convert the input string to an int so it can be manipulated below                tempCounter = Convert.ToInt32(counterStr);//convert temp counter to an int so it can be manipulated below                //spacing for readability                for (int i = 0; i < counter; i++)//for loop to decrement temp counter by 1 with each new number                {                    Console.Write("Please [ENTER] {0} more: ", tempCounter--);//this code is pretty self explanatory. decrement temp counter by 1 with each new number.                    tempNumStr = Console.ReadLine();//same principle as before take input in the form of a string                    Console.WriteLine();//add another line for readability                    tempNum = Convert.ToInt32(tempNumStr);//and convert it to an int to be manipulated                    //spacing for readability                    if (tempNum > largeNum)//if temp num is greater than large num                    {                        largeNum = tempNum;//large num is set to temp num                    }                    //spacing for readability                }//end of decremental for loop                //spacing for readability                Console.WriteLine("The Largest value you input was {0}", largeNum);//output largest number            }//end of a option            //end logical checks for A            //logical checks for B            if (letterChoice == "B" || letterChoice == "b")//if letter choice is equivalent to B or b            {                Console.WriteLine("\nPlease [ENTER] as many numbers as you like (to stop input [ENTER] {0})", STOP);//output instructions to user                //spacing for readability                do// do the following code block while input is not equating to STOP (as demonstrated below)                {                    Console.Write("Please [ENTER] a number: ");//output asking for a number                    tempNumStr = Console.ReadLine();//samee principle as before get input in a string                    tempNum = Convert.ToInt32(tempNumStr);//convert the string to an int for manipulation                    //spacing for readability                    if ((smallNum == 0 || smallNum > tempNum) && tempNum != STOP)//if small number is equal to 0 or if small num is less than temp number and temp number is NOT equavalent to const STOP variable (-999)                    {                        smallNum = tempNum;//small number is set to temp number                    }                }//end of do..while code block                while (tempNum != STOP);//end of do..while for input not equating to -999 (STOP) (as demonstrated above)                //spacing for readability                Console.WriteLine("\nThe smallest value you input was: {0}", smallNum);//output smallest number            }//end of option B            //end logical checks for B            //logical checks for C            if (letterChoice == "C" || letterChoice == "c")//If letter choice is equivalent to C or c            {                Console.WriteLine("\nThanks for trying my menu program! Have a great day!(Press any key)");//output to user to say goodbye                Console.ReadLine();//hold the console open so user can read aforementioned goodbye                leave = true;//set leave to equal true to end the program            }            //end logical checks for C        }//end of while loop for menu    }//end of static non value returning main}//end of control structures class//end of program
Link to comment
https://linustechtips.com/topic/430430-simple-c-program-help/#findComment-5772305
Share on other sites

Link to post
Share on other sites

See I knew it was a simple fix. Lol. In the end the logic running that makes sense. Because smallNum was already 0 and every number over 0 was bigger than 0 (duh) so all I had to do was include a logical check for that. smile.png thanks again. 

 

From what I can see, it looks like because SmallNum is already zero, and every number above zero is bigger than it, it's not changing

 

Lmao I already mentioned it, but no problem happy.png but if a user was to enter 0, then enter a bigger number after that, the bigger number would overwrite it.

Speedtests

WiFi - 7ms, 22Mb down, 10Mb up

Ethernet - 6ms, 47.5Mb down, 9.7Mb up

 

Rigs

Spoiler

 Type            Desktop

 OS              Windows 10 Pro

 CPU             i5-4430S

 RAM             8GB CORSAIR XMS3 (2x4gb)

 Cooler          LC Power LC-CC-97 65W

 Motherboard     ASUS H81M-PLUS

 GPU             GeForce GTX 1060

 Storage         120GB Sandisk SSD (boot), 750GB Seagate 2.5" (storage), 500GB Seagate 2.5" SSHD (cache)

 

Spoiler

Type            Server

OS              Ubuntu 14.04 LTS

CPU             Core 2 Duo E6320

RAM             2GB Non-ECC

Motherboard     ASUS P5VD2-MX SE

Storage         RAID 1: 250GB WD Blue and Seagate Barracuda

Uses            Webserver, NAS, Mediaserver, Database Server

 

Quotes of Fame

On 8/27/2015 at 10:09 AM, Drixen said:

Linus is light years ahead a lot of other YouTubers, he isn't just an average YouTuber.. he's legitimately, legit.

On 10/11/2015 at 11:36 AM, Geralt said:

When something is worth doing, it's worth overdoing.

On 6/22/2016 at 10:05 AM, trag1c said:

It's completely blown out of proportion. Also if you're the least bit worried about data gathering then you should go live in a cave a 1000Km from the nearest establishment simply because every device and every entity gathers information these days. In the current era privacy is just fallacy and nothing more.

 

Link to comment
https://linustechtips.com/topic/430430-simple-c-program-help/#findComment-5772323
Share on other sites

Link to post
Share on other sites

Lmao I already mentioned it, but no problem ^_^ but if a user was to enter 0, then enter a bigger number after that, the bigger number would overwrite it

I guess I misunderstood when you mentioned it before. Sorry about that. I'm kinda fried xD and yeah I know. But I just changed the comments to say that if you input 0, and then 1. The bigger number will overwrite the 0. I think it's fine. 

Link to comment
https://linustechtips.com/topic/430430-simple-c-program-help/#findComment-5772328
Share on other sites

Link to post
Share on other sites

I guess I misunderstood when you mentioned it before. Sorry about that. I'm kinda fried xD and yeah I know. But I just changed the comments to say that if you input 0, and then 1. The bigger number will overwrite the 0. I think it's fine. 

 

oqgmln1.png

 

if you enter any large number, then 0, then any large number after 0, that large number would go into the smallNum variable.

 

You could fix it by setting -999 as the initial smallNum variable (No need to change the STOP variable) then checking to see if smallNum is equal to the STOP variable

Speedtests

WiFi - 7ms, 22Mb down, 10Mb up

Ethernet - 6ms, 47.5Mb down, 9.7Mb up

 

Rigs

Spoiler

 Type            Desktop

 OS              Windows 10 Pro

 CPU             i5-4430S

 RAM             8GB CORSAIR XMS3 (2x4gb)

 Cooler          LC Power LC-CC-97 65W

 Motherboard     ASUS H81M-PLUS

 GPU             GeForce GTX 1060

 Storage         120GB Sandisk SSD (boot), 750GB Seagate 2.5" (storage), 500GB Seagate 2.5" SSHD (cache)

 

Spoiler

Type            Server

OS              Ubuntu 14.04 LTS

CPU             Core 2 Duo E6320

RAM             2GB Non-ECC

Motherboard     ASUS P5VD2-MX SE

Storage         RAID 1: 250GB WD Blue and Seagate Barracuda

Uses            Webserver, NAS, Mediaserver, Database Server

 

Quotes of Fame

On 8/27/2015 at 10:09 AM, Drixen said:

Linus is light years ahead a lot of other YouTubers, he isn't just an average YouTuber.. he's legitimately, legit.

On 10/11/2015 at 11:36 AM, Geralt said:

When something is worth doing, it's worth overdoing.

On 6/22/2016 at 10:05 AM, trag1c said:

It's completely blown out of proportion. Also if you're the least bit worried about data gathering then you should go live in a cave a 1000Km from the nearest establishment simply because every device and every entity gathers information these days. In the current era privacy is just fallacy and nothing more.

 

Link to comment
https://linustechtips.com/topic/430430-simple-c-program-help/#findComment-5772344
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×