Skip to content

Number app#15

Open
martinberntson wants to merge 13 commits into
svenrog:masterfrom
martinberntson:Session03Exercise04
Open

Number app#15
martinberntson wants to merge 13 commits into
svenrog:masterfrom
martinberntson:Session03Exercise04

Conversation

@martinberntson

Copy link
Copy Markdown

App written as part of course assignment.
I tried to make it as difficult as possible for the program to throw a tantrum.

int secondsInput = Convert.ToInt32(Console.ReadLine());
int hours = secondsInput / 3600;
int secondsRemaining = secondsInput % 3600;
int minutes = secondsRemaining / 60;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Toppen, kul att se lösningen!
Den här koden skulle må bra av några tomma rader, här och var, för läsbarhetens skull.
För kompakt text gör det svårare att hitta specifika stycken.

Prova tex innan och efter Console-anrop.

Console.WriteLine("Please enter an amount of time in seconds.");

int secondsInput = Convert.ToInt32(Console.ReadLine());
int hours = secondsInput / 3600;
int secondsRemaining = secondsInput % 3600;
int minutes = secondsRemaining / 60;

Console.WriteLine(secondsInput + " seconds equals " + hours + " hours, " + minutes + " minutes and " + secondsRemaining + " seconds.");
Console.WriteLine("Would you like to continue? (y/n)");
answer = Convert.ToChar(Console.ReadLine());
if (answer == 'n') { looping = false; }

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Placera helst logik som följer en if-sats på en ny rad.
Detta för att du skall kunna skilja på om if-satsen träffats eller inte i debuggern.

if (answer == 'n') 
    looping = false;

{
reversion = String.Concat(reversion, input.Substring(i-1, 1));
}
Console.WriteLine(reversion);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Denna lösning var påhittig!
Hade jag löst den hade jag använt mig av metoden toCharArray() på strängen.
Sedan upprättat en array med samma Length som den ursprungliga och kopierat värdena likt ovan.
Den resulterande strängen kan upprättas med new string(char[]).

{
static void Main(string[] args)
{
Console.WriteLine("Do you want to build a trebuchet? (y/n)");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vem vill inte bygga medeltida belägringsvapen?

Comment thread Session02/Session02Exercise04/Program.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants