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 6241835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:50:22+00:00 2026-05-24T11:50:22+00:00

I am learning C++ and one of the programs was for a random number

  • 0

I am learning C++ and one of the programs was for a random number generator.
Once I wrote the program I got the following errors:

dice.cpp: In function ‘int main()’:
dice.cpp:18: error: pointer to a function used in arithmetic
dice.cpp:18: error: invalid conversion from ‘int (*)(int)’ to ‘int’

Here is my code:

#include<iostream>
#include<cmath>
#include<stdlib.h>
#include<time.h>
using namespace std;
int randn(int n);
int main()
{
  int q;
  int n;
  int r;
  srand(time(NULL));
  cout<<"Enter a number of dice to roll: ";
  cin>>n;
  cout<<endl;

  for (q=1; q<=n; q++)
  {
    r=randn+1;  // <-- error here
    cout<<r<<endl;
  }
  return 0;
}

int randn(int n)
{
  return rand()%n;
}

What could be the problem?

  • 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-05-24T11:50:23+00:00Added an answer on May 24, 2026 at 11:50 am

    I believe that your problem is this line:

    r=randn+1;
    

    I believe that you meant to write

    r = randn(/* some argument */) + 1; // Note parentheses after randn
    

    The issue is that you’re trying to call the function but forgetting to put in the parentheses indicating that you’re making the call. Since you’re trying to roll a six-sided die, this should probably read

    r = randn(6) + 1;
    

    Hope this helps!

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

Sidebar

Related Questions

I'm learning C++ and writing little programs as I go along. The following is
I am learning Objective-C and have completed a simple program and got an unexpected
HI, I started learning C++ STL's i am just trying some small programs.one of
I'm still learning the basics and I'm making a Random Character Generator that creates
I have been following a workshop whilst I'm learning C#. One of the class
I am learning WCF,one of the benefits of WCF is that you can use
I'm learning C++ for one of my CS classes, and for our first project
I have recently started learning Perl and one of my latest assignments involves searching
I'm creating a blog engine as a learning exercise and one particular problem has
I am learning PyQt and wonder if one can create custom/owner draw control like

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.