C
C#•15mo 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•15mo ago
How can a number be less than 0 and more than 35 at the same time?
js
jsOP•15mo 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•15mo ago
&& is and || is or
js
jsOP•15mo ago
on py either way though thats after line 2 and line 2
Angius
Angius•15mo ago
Or if you're used to Python, dpMark is < 0 or > 35
js
jsOP•15mo ago
doesnt let me input anything program jsut closes
Angius
Angius•15mo ago
You mean it closes before you enter anything, or after you type in something?
js
jsOP•15mo 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•15mo 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•15mo ago
yh thats it i removed dpMark and it works like it should
Angius
Angius•15mo ago
Console.WriteLine() with two params works like string.Format()
js
jsOP•15mo ago
up until thjen
Angius
Angius•15mo ago
So it expects the first param to be a template string
js
jsOP•15mo ago
i wasnt sure how to print that
Angius
Angius•15mo ago
And the rest to be params Use string interpolation $"{dpMark} is whatever"
js
jsOP•15mo ago
thank you so much bro šŸ™‚ is there way to say and or
Angius
Angius•15mo ago
Wym "and or"
js
jsOP•15mo ago
ive got two conditions and if one or both of them are true i want it to do something
Angius
Angius•15mo ago
That's an or
js
jsOP•15mo ago
oh yh ig
MODiX
MODiX•15mo 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•15mo 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•15mo ago
No description
Angius
Angius•15mo ago
You already have moduleMark variable declared You cannot redeclare it
js
jsOP•15mo ago
can i not edit it
Angius
Angius•15mo ago
You can moduleMark = 34.0
js
jsOP•15mo ago
do i just remove double oh
Angius
Angius•15mo ago
Yes
js
jsOP•15mo 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•15mo ago
Good time to learn how to $debug
MODiX
MODiX•15mo 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.

Did you find this page helpful?