Score:0

C# function to return string error in unity, not all code paths return a value

us flag

I think there is something wrong with my for loop?


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using BreakInfinity;
using System.Numerics;

public class Notation : MonoBehaviour
{
    public int[] length;
    public string[] letter;

    void Start()
    {
        length = new int[11] { 7,10,13,16,19,21,24,27,30,33,36};
        letter = new string[11] { "K", "M", "B", "T", "q", "Q", "s", "S", "O", "N", "D" };
    }

    public BigDouble Divide(BigDouble num, int power)
    {
        return num / Math.Pow(10, power);
    }

    public string Notate(BigDouble num)
    {
        int digits = num.ToString().Length;

        if (num >= 10000)
        {
            if (digits > 36)
            {
                return "infinite";
            }
            else
            {
                for (int i = 0; i < 11; i++)
                {
                    return Divide(num, digits - 2).ToString("F2") + letter[i];
                }
            }
        }
        else
        {
            return num.ToString();
        }
    }
}

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.