Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8185949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:02:02+00:00 2026-06-07T02:02:02+00:00

I am trying to build an application that rolls dice. Nothing fancy at all.

  • 0

I am trying to build an application that rolls dice. Nothing fancy at all. However, I’m using a segmented control to determine the number of dice and the sides of the dice.

Here is the RollPressed code.

#import "DiceBrain.h"
#import "ViewController.h"

@interface ViewController ()
@property (readonly) DiceBrain *brain;
@end

@implementation ViewController

- (DiceBrain *) brain {
    if (!brain) brain = [[DiceBrain alloc] init];
    return brain;
}

- (IBAction)RollPressed:(id)sender {
    int num_dice = dice.selectedSegmentIndex;
    int num_sides = sides.selectedSegmentIndex;
    NSLog(@"Number of Dice is %u and Number of Sides is %u", num_dice, num_sides);
    int result = [self.brain RollDice:num_dice Sides: num_sides];
    display.text = [NSString stringWithFormat:@"%g", result];
}

@end

According to NSLog there, I’m always using a zero. Of course, actuating using this logic to roll the dice results in the display showing me something like 3.82652e-308.
The logic used to roll the dice is

- (int)RollDice:(int)dice Sides:(int)num_sides{
    total = 0;

    for (int i = 0; i < dice; i++) {
        total += (arc4random() % num_sides) + 1;
    }

    return total;
}

What could cause the segmented control to give me such funky results?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:02:03+00:00Added an answer on June 7, 2026 at 2:02 am

    Sounds like your IBOutlets for sides and dice are not connected.

    Check their value; it’s probably NULL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a application that has different kinds of users, I'm using
I'm trying to build a c# application that displays and invokes all of a
I trying to build an application that is using the torrent technology to make
I'm trying to build application that could help me dial a contact just like
I'm trying to build an application that builds a resource file into a jar,
i'm trying to build an application that every given time, will connect to a
I am trying to build a Python application that connects to Oracle database and
I'm trying to build a web application that uses an SSL connection. So I
I'm trying to build an iPhone application that has two subviews in the main
as titled, am trying to build a small application that will aggregate RSS from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.