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
$ask
How to get the best help
Make a post in #help or one of the topic channels under Development.
Avoid asking Can anybody help Has anyone used 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.hi @SinFluxx
will me posting a pic of the code help u?
better to $paste the code
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!
$code
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/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
ok, so you obviously want to assign what the user enters to your dad/me/mom variables?
write ` this symbol three times at the start and end of your code, so it formats it better, like this:
what has changed here?
Nothing, just looks nicer
in discord
easier for people trying to help you to read it
ok thx
wdym?
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 :
as an example
oh ok
you are reading, but not storing the value read anywhere
yeah ok
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
ok thx aklot
alot
nor parsing them
hi
Console.ReadLine()
returns a stringits 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?
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 useroh ok
lemme fix it
what's that
Double
struct doingwdym?
Double
ok
what does it do
it gives the thing i put in it a value of a number that is decimal
doesnt it?
ok, does your code build?
what do u mean by "build"?
double
and decimal
are two different typesok
do you have errors?
yes bu i restarted the code cause i f'd it in the order
aight
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
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?
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
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
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.0Console.ReadLine Method (System)
Reads the next line of characters from the standard input stream.
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.
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
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.