❔ returning an array from a substring
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
internal class Program
{
static int[] studentMarks = new int[5];
static int[] percentage = new int[5];
static void Main(string[] args)
{
InputAllMarks(); ConvertToPercentage(); for (int i = 0; i < 5; i++) { Console.WriteLine(percentage[i]); }
Console.ReadLine(); } static void InputAllMarks() { for (int i = 0; i < 5; i++) { Console.WriteLine("Please enter your marks"); studentMarks[i] = int.Parse(Console.ReadLine()); } } static int[] ConvertToPercentage() { for (int i = 0; i < 5; i++) { percentage[i] = studentMarks[i] / 60 * 100;
} return percentage; } } } Can anyone tell me why this returns 0 in The array percentage ?
InputAllMarks(); ConvertToPercentage(); for (int i = 0; i < 5; i++) { Console.WriteLine(percentage[i]); }
Console.ReadLine(); } static void InputAllMarks() { for (int i = 0; i < 5; i++) { Console.WriteLine("Please enter your marks"); studentMarks[i] = int.Parse(Console.ReadLine()); } } static int[] ConvertToPercentage() { for (int i = 0; i < 5; i++) { percentage[i] = studentMarks[i] / 60 * 100;
} return percentage; } } } Can anyone tell me why this returns 0 in The array percentage ?
6 Replies
$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/int
s don't do decimals, they only do whole numbersit's time to use
float
sOh lmao yeah
I’m stupid
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.