Simple c sharp calculator improvement suggestions
up vote
1
down vote
favorite
I'm doing simple calc for my school. Code looks okay to me, not sure if there is something to improve, but probably there is always something to improve. Any ideas how to make it look and work better?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace kalkulacka
{
class Program
{
static void Main(string args)
{
Console.WriteLine("Daniel Nosek");
Console.WriteLine("Výpočet obvodu a obsahu - trojúhelník, pravidelný šestiúhelník");
Console.WriteLine("Zvolte si obrazec:");
Console.WriteLine("1 - trojúhelník");
Console.WriteLine("2 - pravidelný šestiúhelník");
int VolbaObrazce = int.Parse(Console.ReadLine());
double obvod = 0;
double obsah = 0;
bool prepocitat = false;
do
{
Console.Clear();
switch (VolbaObrazce)
{
case 1:
double a = PrectiPromennou("Zadejte délku strany a:");
double b = PrectiPromennou("Zadejte délku strany b:");
double c = PrectiPromennou("Zadejte délku strany c:");
obvod = ObvodTrojuhelniku(a, b, c);
obsah = ObsahTrojuhelniku(a, b, c);
break;
case 2:
double d = PrectiPromennou("Zadejte délku strany d:");
obvod = ObvodSestiuhelniku(d);
obsah = ObsahSestiuhelniku(d);
break;
default:
{
Console.WriteLine("Neplatná volba");
}
return;
}
// vysledky, zaokrouhleny na dve desetinna mista
Console.WriteLine("obvod: " + Math.Round(obvod, 2));
Console.WriteLine("obsah: " + Math.Round(obsah, 2));
/* loop pro pripad kdy uzivatel chce vypocet znova s jinymi hodnotami
promenna recalculate musi byt rovna 1, jinak se program vypne */
prepocitat = PrectiPromennou("Pro výpočet s jinými rozměry stiskněte 1:") == 1;
}
while (prepocitat);
}
/*Puvodne jsem pouzival pri cases
Console.WriteLine("Zadejte délku strany x:");
double x = double.Parse(Console.ReadLine());
nicmene resit to takhle mi prijde jednodussi.*/
static double PrectiPromennou(string text)
{
Console.Write(text);
return double.Parse(Console.ReadLine());
}
/// <summary>
/// Vypocet obvodu pomoci souctu stran
/// </summary>
/// <param name="a">delka strany a</param>
/// <param name="b">delka strany b</param>
/// <param name="c">delka strany c</param>
/// <returns>obvod trojuhelniku</returns>
static double ObvodTrojuhelniku(double a, double b, double c)
{
return a + b + c;
}
/// <summary>
/// Vypocet obsahu pomoci heronova vzorce
/// </summary>
/// <param name="a">delka strany a</param>
/// <param name="b">delka strany b</param>
/// <param name="c">delka strany c</param>
/// <returns>obsah trojuhelniku</returns>
static double ObsahTrojuhelniku(double a, double b, double c)
{
double s = (a + b + c) / 2;
return Math.Sqrt(s * (s - a) * (s - b) * (s - c));
}
/// <summary>
/// Vypocet obvodu pomoci soucinu stran
/// </summary>
/// <param name="d">delka strany d</param>
/// <returns>obvod sestiuhelniku</returns>
static double ObvodSestiuhelniku(double d)
{
return 6 * d;
}
/// <summary>
/// vypocet obsahu
/// </summary>
/// <param name="d">delka strany d</param>
/// <returns>obsah sestiuhelniku</returns>
static double ObsahSestiuhelniku(double d)
{
return ((3 * Math.Sqrt(3) * Math.Pow(d, 2))) / 2;
}
}
}
c#
New contributor
add a comment |
up vote
1
down vote
favorite
I'm doing simple calc for my school. Code looks okay to me, not sure if there is something to improve, but probably there is always something to improve. Any ideas how to make it look and work better?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace kalkulacka
{
class Program
{
static void Main(string args)
{
Console.WriteLine("Daniel Nosek");
Console.WriteLine("Výpočet obvodu a obsahu - trojúhelník, pravidelný šestiúhelník");
Console.WriteLine("Zvolte si obrazec:");
Console.WriteLine("1 - trojúhelník");
Console.WriteLine("2 - pravidelný šestiúhelník");
int VolbaObrazce = int.Parse(Console.ReadLine());
double obvod = 0;
double obsah = 0;
bool prepocitat = false;
do
{
Console.Clear();
switch (VolbaObrazce)
{
case 1:
double a = PrectiPromennou("Zadejte délku strany a:");
double b = PrectiPromennou("Zadejte délku strany b:");
double c = PrectiPromennou("Zadejte délku strany c:");
obvod = ObvodTrojuhelniku(a, b, c);
obsah = ObsahTrojuhelniku(a, b, c);
break;
case 2:
double d = PrectiPromennou("Zadejte délku strany d:");
obvod = ObvodSestiuhelniku(d);
obsah = ObsahSestiuhelniku(d);
break;
default:
{
Console.WriteLine("Neplatná volba");
}
return;
}
// vysledky, zaokrouhleny na dve desetinna mista
Console.WriteLine("obvod: " + Math.Round(obvod, 2));
Console.WriteLine("obsah: " + Math.Round(obsah, 2));
/* loop pro pripad kdy uzivatel chce vypocet znova s jinymi hodnotami
promenna recalculate musi byt rovna 1, jinak se program vypne */
prepocitat = PrectiPromennou("Pro výpočet s jinými rozměry stiskněte 1:") == 1;
}
while (prepocitat);
}
/*Puvodne jsem pouzival pri cases
Console.WriteLine("Zadejte délku strany x:");
double x = double.Parse(Console.ReadLine());
nicmene resit to takhle mi prijde jednodussi.*/
static double PrectiPromennou(string text)
{
Console.Write(text);
return double.Parse(Console.ReadLine());
}
/// <summary>
/// Vypocet obvodu pomoci souctu stran
/// </summary>
/// <param name="a">delka strany a</param>
/// <param name="b">delka strany b</param>
/// <param name="c">delka strany c</param>
/// <returns>obvod trojuhelniku</returns>
static double ObvodTrojuhelniku(double a, double b, double c)
{
return a + b + c;
}
/// <summary>
/// Vypocet obsahu pomoci heronova vzorce
/// </summary>
/// <param name="a">delka strany a</param>
/// <param name="b">delka strany b</param>
/// <param name="c">delka strany c</param>
/// <returns>obsah trojuhelniku</returns>
static double ObsahTrojuhelniku(double a, double b, double c)
{
double s = (a + b + c) / 2;
return Math.Sqrt(s * (s - a) * (s - b) * (s - c));
}
/// <summary>
/// Vypocet obvodu pomoci soucinu stran
/// </summary>
/// <param name="d">delka strany d</param>
/// <returns>obvod sestiuhelniku</returns>
static double ObvodSestiuhelniku(double d)
{
return 6 * d;
}
/// <summary>
/// vypocet obsahu
/// </summary>
/// <param name="d">delka strany d</param>
/// <returns>obsah sestiuhelniku</returns>
static double ObsahSestiuhelniku(double d)
{
return ((3 * Math.Sqrt(3) * Math.Pow(d, 2))) / 2;
}
}
}
c#
New contributor
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm doing simple calc for my school. Code looks okay to me, not sure if there is something to improve, but probably there is always something to improve. Any ideas how to make it look and work better?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace kalkulacka
{
class Program
{
static void Main(string args)
{
Console.WriteLine("Daniel Nosek");
Console.WriteLine("Výpočet obvodu a obsahu - trojúhelník, pravidelný šestiúhelník");
Console.WriteLine("Zvolte si obrazec:");
Console.WriteLine("1 - trojúhelník");
Console.WriteLine("2 - pravidelný šestiúhelník");
int VolbaObrazce = int.Parse(Console.ReadLine());
double obvod = 0;
double obsah = 0;
bool prepocitat = false;
do
{
Console.Clear();
switch (VolbaObrazce)
{
case 1:
double a = PrectiPromennou("Zadejte délku strany a:");
double b = PrectiPromennou("Zadejte délku strany b:");
double c = PrectiPromennou("Zadejte délku strany c:");
obvod = ObvodTrojuhelniku(a, b, c);
obsah = ObsahTrojuhelniku(a, b, c);
break;
case 2:
double d = PrectiPromennou("Zadejte délku strany d:");
obvod = ObvodSestiuhelniku(d);
obsah = ObsahSestiuhelniku(d);
break;
default:
{
Console.WriteLine("Neplatná volba");
}
return;
}
// vysledky, zaokrouhleny na dve desetinna mista
Console.WriteLine("obvod: " + Math.Round(obvod, 2));
Console.WriteLine("obsah: " + Math.Round(obsah, 2));
/* loop pro pripad kdy uzivatel chce vypocet znova s jinymi hodnotami
promenna recalculate musi byt rovna 1, jinak se program vypne */
prepocitat = PrectiPromennou("Pro výpočet s jinými rozměry stiskněte 1:") == 1;
}
while (prepocitat);
}
/*Puvodne jsem pouzival pri cases
Console.WriteLine("Zadejte délku strany x:");
double x = double.Parse(Console.ReadLine());
nicmene resit to takhle mi prijde jednodussi.*/
static double PrectiPromennou(string text)
{
Console.Write(text);
return double.Parse(Console.ReadLine());
}
/// <summary>
/// Vypocet obvodu pomoci souctu stran
/// </summary>
/// <param name="a">delka strany a</param>
/// <param name="b">delka strany b</param>
/// <param name="c">delka strany c</param>
/// <returns>obvod trojuhelniku</returns>
static double ObvodTrojuhelniku(double a, double b, double c)
{
return a + b + c;
}
/// <summary>
/// Vypocet obsahu pomoci heronova vzorce
/// </summary>
/// <param name="a">delka strany a</param>
/// <param name="b">delka strany b</param>
/// <param name="c">delka strany c</param>
/// <returns>obsah trojuhelniku</returns>
static double ObsahTrojuhelniku(double a, double b, double c)
{
double s = (a + b + c) / 2;
return Math.Sqrt(s * (s - a) * (s - b) * (s - c));
}
/// <summary>
/// Vypocet obvodu pomoci soucinu stran
/// </summary>
/// <param name="d">delka strany d</param>
/// <returns>obvod sestiuhelniku</returns>
static double ObvodSestiuhelniku(double d)
{
return 6 * d;
}
/// <summary>
/// vypocet obsahu
/// </summary>
/// <param name="d">delka strany d</param>
/// <returns>obsah sestiuhelniku</returns>
static double ObsahSestiuhelniku(double d)
{
return ((3 * Math.Sqrt(3) * Math.Pow(d, 2))) / 2;
}
}
}
c#
New contributor
I'm doing simple calc for my school. Code looks okay to me, not sure if there is something to improve, but probably there is always something to improve. Any ideas how to make it look and work better?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace kalkulacka
{
class Program
{
static void Main(string args)
{
Console.WriteLine("Daniel Nosek");
Console.WriteLine("Výpočet obvodu a obsahu - trojúhelník, pravidelný šestiúhelník");
Console.WriteLine("Zvolte si obrazec:");
Console.WriteLine("1 - trojúhelník");
Console.WriteLine("2 - pravidelný šestiúhelník");
int VolbaObrazce = int.Parse(Console.ReadLine());
double obvod = 0;
double obsah = 0;
bool prepocitat = false;
do
{
Console.Clear();
switch (VolbaObrazce)
{
case 1:
double a = PrectiPromennou("Zadejte délku strany a:");
double b = PrectiPromennou("Zadejte délku strany b:");
double c = PrectiPromennou("Zadejte délku strany c:");
obvod = ObvodTrojuhelniku(a, b, c);
obsah = ObsahTrojuhelniku(a, b, c);
break;
case 2:
double d = PrectiPromennou("Zadejte délku strany d:");
obvod = ObvodSestiuhelniku(d);
obsah = ObsahSestiuhelniku(d);
break;
default:
{
Console.WriteLine("Neplatná volba");
}
return;
}
// vysledky, zaokrouhleny na dve desetinna mista
Console.WriteLine("obvod: " + Math.Round(obvod, 2));
Console.WriteLine("obsah: " + Math.Round(obsah, 2));
/* loop pro pripad kdy uzivatel chce vypocet znova s jinymi hodnotami
promenna recalculate musi byt rovna 1, jinak se program vypne */
prepocitat = PrectiPromennou("Pro výpočet s jinými rozměry stiskněte 1:") == 1;
}
while (prepocitat);
}
/*Puvodne jsem pouzival pri cases
Console.WriteLine("Zadejte délku strany x:");
double x = double.Parse(Console.ReadLine());
nicmene resit to takhle mi prijde jednodussi.*/
static double PrectiPromennou(string text)
{
Console.Write(text);
return double.Parse(Console.ReadLine());
}
/// <summary>
/// Vypocet obvodu pomoci souctu stran
/// </summary>
/// <param name="a">delka strany a</param>
/// <param name="b">delka strany b</param>
/// <param name="c">delka strany c</param>
/// <returns>obvod trojuhelniku</returns>
static double ObvodTrojuhelniku(double a, double b, double c)
{
return a + b + c;
}
/// <summary>
/// Vypocet obsahu pomoci heronova vzorce
/// </summary>
/// <param name="a">delka strany a</param>
/// <param name="b">delka strany b</param>
/// <param name="c">delka strany c</param>
/// <returns>obsah trojuhelniku</returns>
static double ObsahTrojuhelniku(double a, double b, double c)
{
double s = (a + b + c) / 2;
return Math.Sqrt(s * (s - a) * (s - b) * (s - c));
}
/// <summary>
/// Vypocet obvodu pomoci soucinu stran
/// </summary>
/// <param name="d">delka strany d</param>
/// <returns>obvod sestiuhelniku</returns>
static double ObvodSestiuhelniku(double d)
{
return 6 * d;
}
/// <summary>
/// vypocet obsahu
/// </summary>
/// <param name="d">delka strany d</param>
/// <returns>obsah sestiuhelniku</returns>
static double ObsahSestiuhelniku(double d)
{
return ((3 * Math.Sqrt(3) * Math.Pow(d, 2))) / 2;
}
}
}
c#
c#
New contributor
New contributor
edited 2 hours ago
janos
96.7k12124350
96.7k12124350
New contributor
asked 4 hours ago
NoobStudent
62
62
New contributor
New contributor
add a comment |
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
NoobStudent is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f209714%2fsimple-c-sharp-calculator-improvement-suggestions%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
NoobStudent is a new contributor. Be nice, and check out our Code of Conduct.
NoobStudent is a new contributor. Be nice, and check out our Code of Conduct.
NoobStudent is a new contributor. Be nice, and check out our Code of Conduct.
NoobStudent is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f209714%2fsimple-c-sharp-calculator-improvement-suggestions%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown