C
C#ā€¢10mo ago
js

program closing early

Console.WriteLine("What was the digital portfolio mark (out of 35)?");
int dpMark = int.Parse(Console.ReadLine());
if(dpMark < 0 && dpMark > 35)
{
Console.WriteLine("hello");
}
else
{
Console.WriteLine(dpMark," is not a valid mark for the digital portfolio");
}
Console.WriteLine("What was the digital portfolio mark (out of 35)?");
int dpMark = int.Parse(Console.ReadLine());
if(dpMark < 0 && dpMark > 35)
{
Console.WriteLine("hello");
}
else
{
Console.WriteLine(dpMark," is not a valid mark for the digital portfolio");
}
when i try to run my code the program exits after line 1?
No description
31 Replies
Angius
Angiusā€¢10mo ago
How can a number be less than 0 and more than 35 at the same time?
js
jsOPā€¢10mo ago
i was trying to put less than 0 or greater than i thought that was the right one im used to just putting or
Angius
Angiusā€¢10mo ago
&& is and || is or
js
jsOPā€¢10mo ago
on py either way though thats after line 2 and line 2
Angius
Angiusā€¢10mo ago
Or if you're used to Python, dpMark is < 0 or > 35
js
jsOPā€¢10mo ago
doesnt let me input anything program jsut closes
Angius
Angiusā€¢10mo ago
You mean it closes before you enter anything, or after you type in something?
js
jsOPā€¢10mo ago
before as soon as i run it and i dont get it i used the same parse line on my previous assignment 5 minutes ago and it worked only thing diff is variable name
Angius
Angiusā€¢10mo ago
I wonder if it runs a previous version of the project I have a suspicion that
Console.WriteLine(dpMark," is not a valid mark for the digital portfolio");
Console.WriteLine(dpMark," is not a valid mark for the digital portfolio");
prevents it from compiling
js
jsOPā€¢10mo ago
yh thats it i removed dpMark and it works like it should
Angius
Angiusā€¢10mo ago
Console.WriteLine() with two params works like string.Format()
js
jsOPā€¢10mo ago
up until thjen
Angius
Angiusā€¢10mo ago
So it expects the first param to be a template string
js
jsOPā€¢10mo ago
i wasnt sure how to print that
Angius
Angiusā€¢10mo ago
And the rest to be params Use string interpolation $"{dpMark} is whatever"
js
jsOPā€¢10mo ago
thank you so much bro šŸ™‚ is there way to say and or
Angius
Angiusā€¢10mo ago
Wym "and or"
js
jsOPā€¢10mo ago
ive got two conditions and if one or both of them are true i want it to do something
Angius
Angiusā€¢10mo ago
That's an or
js
jsOPā€¢10mo ago
oh yh ig
MODiX
MODiXā€¢10mo ago
Angius
REPL Result: Success
record Check(bool A, bool B);
var checks = new Check[]{
new (true, true),
new (true, false),
new (false, true),
new (false, false),
};
foreach (var c in checks)
{
Console.WriteLine($"{c.A} && {c.B} => {c.A && c.B}");
Console.WriteLine($"{c.A} || {c.B} => {c.A || c.B}");
}
record Check(bool A, bool B);
var checks = new Check[]{
new (true, true),
new (true, false),
new (false, true),
new (false, false),
};
foreach (var c in checks)
{
Console.WriteLine($"{c.A} && {c.B} => {c.A && c.B}");
Console.WriteLine($"{c.A} || {c.B} => {c.A || c.B}");
}
Console Output
True && True => True
True || True => True
True && False => False
True || False => True
False && True => False
False || True => True
False && False => False
False || False => False
True && True => True
True || True => True
True && False => False
True || False => True
False && True => False
False || True => True
False && False => False
False || False => False
Compile: 567.787ms | Execution: 83.022ms | React with āŒ to remove this embed.
js
jsOPā€¢10mo ago
Console.WriteLine("What was the digital portfolio mark (out of 35)?");
int dpMark = int.Parse(Console.ReadLine());
if(dpMark < 0 || dpMark > 35)
{
Console.WriteLine($"{dpMark} is not a valid mark for the digital portfolio");
}
else
{
Console.WriteLine("What was the open book programming mark (out of 7)?");
int obpMark = int.Parse(Console.ReadLine());
if (obpMark < 0 || obpMark > 7)
{
Console.WriteLine($"{obpMark} is not a valid mark for the open book programming exam");
}
else
{
Console.WriteLine("What was the capstone project mark (out of 100)?");
int cpMark = int.Parse(Console.ReadLine());
if (cpMark < 0 || cpMark > 100)
{
Console.WriteLine($"{cpMark} is not a valid mark for the capstone project");
}
else
{
double dpPerc = (dpMark / 35) * 100;
double obpPerc = (obpMark / 7) * 100;
double cpPerc = (cpMark / 100) * 100;
double totalPerc = (((dpPerc * 50) / 100) + ((obpPerc * 25) / 100) + ((cpPerc * 25) / 100));
double moduleMark = (float)Math.Round(totalPerc, 2);
if((obpPerc < 40 || cpPerc < 40) && moduleMark > 34)
{
double moduleMark = 34.00;
}
}
}
}
Console.WriteLine("What was the digital portfolio mark (out of 35)?");
int dpMark = int.Parse(Console.ReadLine());
if(dpMark < 0 || dpMark > 35)
{
Console.WriteLine($"{dpMark} is not a valid mark for the digital portfolio");
}
else
{
Console.WriteLine("What was the open book programming mark (out of 7)?");
int obpMark = int.Parse(Console.ReadLine());
if (obpMark < 0 || obpMark > 7)
{
Console.WriteLine($"{obpMark} is not a valid mark for the open book programming exam");
}
else
{
Console.WriteLine("What was the capstone project mark (out of 100)?");
int cpMark = int.Parse(Console.ReadLine());
if (cpMark < 0 || cpMark > 100)
{
Console.WriteLine($"{cpMark} is not a valid mark for the capstone project");
}
else
{
double dpPerc = (dpMark / 35) * 100;
double obpPerc = (obpMark / 7) * 100;
double cpPerc = (cpMark / 100) * 100;
double totalPerc = (((dpPerc * 50) / 100) + ((obpPerc * 25) / 100) + ((cpPerc * 25) / 100));
double moduleMark = (float)Math.Round(totalPerc, 2);
if((obpPerc < 40 || cpPerc < 40) && moduleMark > 34)
{
double moduleMark = 34.00;
}
}
}
}
why is it not letting me set moduleMark to 34 at the bottom everything else is fine i think but
js
jsOPā€¢10mo ago
No description
Angius
Angiusā€¢10mo ago
You already have moduleMark variable declared You cannot redeclare it
js
jsOPā€¢10mo ago
can i not edit it
Angius
Angiusā€¢10mo ago
You can moduleMark = 34.0
js
jsOPā€¢10mo ago
do i just remove double oh
Angius
Angiusā€¢10mo ago
Yes
js
jsOPā€¢10mo ago
its working but i got the maths wrong somewhere šŸ˜­ my invalid mark lines work but if im putting all valid inputs in im getting an output score of 0 everytime šŸ˜­
Angius
Angiusā€¢10mo ago
Good time to learn how to $debug
MODiX
MODiXā€¢10mo ago
Tutorial: Debug C# code and inspect data - Visual Studio (Windows)
Learn features of the Visual Studio debugger and how to start the debugger, step through code, and inspect data in a C# application.
Want results from more Discord servers?
Add your server