Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Number app #15

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

martinberntson
Copy link

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
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
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
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
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?

Session02/Session02Exercise04/Program.cs Show resolved Hide resolved
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