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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:32:01+00:00 2026-06-18T01:32:01+00:00

I want a table of four values between 1 to 6. I’m using: rand()

  • 0

I want a table of four values between 1 to 6.

I’m using: rand() % 6 + 1;

This should give values between 1 and 6.

Except if rand() generates the value 0.

  1. I keep getting 7’s. I don’t want any 7’s

  2. What is the range of rand? How I prevent it from generation any 0 values?

  3. Alternative solutions are quite welcome.

  4. My teacher gave us the clue of using “random”.
    We use Borland C++ Builder 5 at school.
    I am using Dev-C++ 5.3.0.3 at home.
    I find there are a few differences to how they work, which I find strange..
    I can’t use random(), it gives me not declared in scope…

    int main (){
    
        int I;
        int Fasit[3];
    
        srand (time(NULL) );
    
        for(I=0; I<4; I++) {
            Fasit[I]=rand() % 6 + 1;
        }
    
        std::cout << Fasit[0] << " " << Fasit[1] << " " << Fasit[2] << " " << Fasit[3] << " ";
    
        return 0;
    }
    

Some values I get:

2 6 1 7  
5 2 1 4  
5 2 1 4  
5 2 1 4  
1 3 1 6  
5 3 3 7  
5 3 3 7  
5 3 3 7

7 shouldn’t be possible, should it?

PS: I know my print is ham fisted, I will make it a bit more elegant once the number generation works.

  • 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-18T01:32:02+00:00Added an answer on June 18, 2026 at 1:32 am

    Consdier these lines:

    int Fasit[3];
    for(I=0; I<4; I++) {
      Fasit[I]
    

    You declare an array of three entries, which you write to four times.

    Try your program again, but with:

    int Fasit[4];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a table named item with four attribute name,code,class,value now i want to
this table i want to create job_id dynamic Jobs Title text Job Description text
I have a table with four columns, where col1 & col2 contain similar values
I have a row in table PRVO with four type of values : first,
hi all i want to display database values in chart. for example a table
I have a relationship table in my database that has four values AKA... id,
i have a table named record which contains four column branch,account,name,month. now i want
I want to update the values of one column in a table from '0'
I have two tables and two buttons. I want table-1 to be in the
I want a table rendered by django-tables2 to be drawn over the whole screen.

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.