C
C#13mo ago
shemesh

Need help with a school project which is very beginner level, would very much like someone to help/

i need somone to help me understand whats wrong with the code i put.
47 Replies
SinFluxx
SinFluxx13mo ago
$ask
MODiX
MODiX13mo ago
How to get the best help catpog Make a post in #help or one of the topic channels under Development. Avoid askingcatthinking Can anybody help catthinking Has anyone used catthinking Why doesn't my code work? C# is a big area! No one knows they can help unless you tell them about the small area you're trying to work in. Explain what you are doing, and potentially why for as much context as possible. Avoid screenshots where possible, share code directly in Discord. Type $code into chat to learn how to post code. See https://www.nohello.net and https://dontasktoask.com if you want common help chat room etiquette.
shemesh
shemeshOP13mo ago
hi @SinFluxx will me posting a pic of the code help u?
SinFluxx
SinFluxx13mo ago
better to $paste the code
MODiX
MODiX13mo ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
SinFluxx
SinFluxx13mo ago
$code
MODiX
MODiX13mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
shemesh
shemeshOP13mo ago
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace averege { internal class Program { static void Main(string[] args) { Double dad, me, mom, age; Console.Write("What is your age? "); Console.ReadLine(); Console.Write("What is your mom's age? "); Console.ReadLine(); Console.Write("What is your dad's age? "); Console.ReadLine(); age = mom + dad + me / 3; Console.ReadKey; } } } i need to make it so it calculates the averege age of me and my family i just started coding like 2 weeks ago
SinFluxx
SinFluxx13mo ago
ok, so you obviously want to assign what the user enters to your dad/me/mom variables?
walter9830
walter983013mo ago
write ` this symbol three times at the start and end of your code, so it formats it better, like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace averege
{
internal class Program
{
static void Main(string[] args)
{
Double dad, me, mom, age;
Console.Write("What is your age? ");
Console.ReadLine();
Console.Write("What is your mom's age? ");
Console.ReadLine();
Console.Write("What is your dad's age? ");
Console.ReadLine();
age = mom + dad + me / 3;
Console.ReadKey;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace averege
{
internal class Program
{
static void Main(string[] args)
{
Double dad, me, mom, age;
Console.Write("What is your age? ");
Console.ReadLine();
Console.Write("What is your mom's age? ");
Console.ReadLine();
Console.Write("What is your dad's age? ");
Console.ReadLine();
age = mom + dad + me / 3;
Console.ReadKey;
}
}
}
shemesh
shemeshOP13mo ago
what has changed here?
walter9830
walter983013mo ago
Nothing, just looks nicer in discord
SinFluxx
SinFluxx13mo ago
easier for people trying to help you to read it
shemesh
shemeshOP13mo ago
ok thx wdym?
walter9830
walter983013mo ago
When doing Console.Readline() you read a value from the console, however you don't store it anywhere so for example, in your case, if you wanted to get the age of mom from the console you would do :
double mom = Console.Readline();
double mom = Console.Readline();
as an example
shemesh
shemeshOP13mo ago
oh ok
walter9830
walter983013mo ago
you are reading, but not storing the value read anywhere
shemesh
shemeshOP13mo ago
yeah ok
walter9830
walter983013mo ago
You are also not displaying the value calculated anywhere use Console.Writeline to display the age after its calculated, easier to see whats going on. Unfortunately I have to go but good luck, your main issue is that you are not storing your values anywhere
shemesh
shemeshOP13mo ago
ok thx aklot alot
SG97
SG9713mo ago
nor parsing them
shemesh
shemeshOP13mo ago
hi
SG97
SG9713mo ago
Console.ReadLine() returns a string
shemesh
shemeshOP13mo ago
its now looking like this using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace averege { internal class Program { static void Main(string[] args) { Double dad, me, mom, age; Console.Write("What is your age? "); mom = Double(Console.ReadLine()); dad = Double(Console.ReadLine()); me = Double(Console.ReadLine()); age = (me + mom + dad) / 3; Console.Write("What is your mom's age? "); Console.ReadLine(); Console.Write("What is your dad's age? "); Console.ReadLine(); Console.WriteLine(" The averege age of your family is: " + age); Console.ReadKey; } } } whats the problem now?
Pobiega
Pobiega13mo ago
look at the order Console.ReadLine() is the method that takes the user input, so look at when you do that in relation to when you print the instructions to the user
shemesh
shemeshOP13mo ago
oh ok lemme fix it
SG97
SG9713mo ago
what's that Double struct doing
shemesh
shemeshOP13mo ago
wdym?
SG97
SG9713mo ago
Double
shemesh
shemeshOP13mo ago
ok
SG97
SG9713mo ago
what does it do
shemesh
shemeshOP13mo ago
it gives the thing i put in it a value of a number that is decimal doesnt it?
SG97
SG9713mo ago
ok, does your code build?
shemesh
shemeshOP13mo ago
what do u mean by "build"?
SG97
SG9713mo ago
double and decimal are two different types
shemesh
shemeshOP13mo ago
ok
SG97
SG9713mo ago
do you have errors?
shemesh
shemeshOP13mo ago
yes bu i restarted the code cause i f'd it in the order
SG97
SG9713mo ago
aight
shemesh
shemeshOP13mo ago
what is the order supposed to be like? and how do i make the question "what is yoyur age " include the variable "me" @sn0wgirl_97 i would appreciate if i could call or smth and share my screen
Pobiega
Pobiega13mo ago
That shouldn't be needed the order should be self-explanatory Do you normally expect people to answer before you ask them a question in real life?
SG97
SG9713mo ago
you use the Console.ReadLine() to get the input from the user. Ask the question Console.Write first, then get the user input you still need to convert from a string to a double
shemesh
shemeshOP13mo ago
ight i did it namespace averege { internal class Program { static void Main(string[] args) { Double mom, dad, me, age; Console.Write("What is your age? "); me = Double.Parse(Console.ReadLine()); Console.WriteLine("What is your mom's age? "); mom = Double.Parse(Console.ReadLine()); Console.WriteLine("What is your dad's age? "); dad = Double.Parse(Console.ReadLine()); age = (me + dad + mom) / 3; Console.WriteLine("The averege age of your family is: " + age); Console.ReadKey(); } } } thank you
Mango
Mango13mo ago
I know this has already been answered but @walter here is additional context as to WHY you should assign. Console.ReadLine() returns what the user typed after they hit enter. https://learn.microsoft.com/en-us/dotnet/api/system.console.readline?view=net-7.0
Console.ReadLine Method (System)
Reads the next line of characters from the standard input stream.
Mango
Mango13mo ago
If you don’t understand the concept of “a method returning” something, you should read up on that first. Otherwise you won’t be able to program much of anything.
walter9830
walter983013mo ago
Building means preparing the code, doing syntax checks etc. In simple terms I wouldn’t get deeper into it for now you will lose the enthusiasm for coding if you start reading about how building or compiling works For now just understand that there are several stages of “checks” and “preparation” before your code launches Just as an airplane has to be checked before takeoff Building and compiling checks if the code is good to go and is written correctly
Accord
Accord13mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server