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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:55:01+00:00 2026-06-11T14:55:01+00:00

I have a problem with a For Loop. I need it to count a

  • 0

I have a problem with a For Loop. I need it to count a random amount of shopping sprees and amounts but display them in order like below. It also needs to take the amount of sprees and display it before.

Currently it displays total sprees as 0 and only displays 20 sprees which is not random.

You have won a total of 3 shopping sprees

On spree #1 you may spend R100

On spree #2 you may spend R341

On spree #3 you may spend R451

TotalCost := 0;

Sum := 0;

ListHead := 'Max per spree is R500.00 Max number of sprees 20';
lstNumber.Items.Add(ListHead);

  SpreeWon := 'You have won  ' + inttostr(Sum) + ' shopping sprees';
  lstNumber.Items.Add(SpreeWon);

for Count := 0 to 20 do
begin
    Sum := Random(Count);
    Prize := Random(500) + 1;
    ListItems := 'On spree # ' + inttostr(Sum) + ' you may spend R' + inttostr(Prize);
    lstNumber.Items.Add(ListItems);
    TotalCost := TotalCost + Prize;
end;
begin
    Cost := 'Total prize value : R' + inttostr(TotalCost);
    lstNumber.Items.Add(Cost);
end;
  • 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-11T14:55:02+00:00Added an answer on June 11, 2026 at 2:55 pm

    Your code is not doing what your requirement asks for. You are displaying 20 sprees because you hard-coded it to generate 20 sprees, not a random number of sprees.

    Try something more like this instead:

    ListHead := 'Max per spree is R500.00 Max number of sprees 20';
    lstNumber.Items.Add(ListHead);
    
    Count := Random(20) + 1;
    TotalCost := 0;
    
    SpreeWon := 'You have won  ' + IntToStr(Count) + ' shopping sprees';
    lstNumber.Items.Add(SpreeWon);
    
    for I := 1 to Count do
    begin
      Prize := Random(500) + 1;
      TotalCost := TotalCost + Prize;
      ListItems := 'On spree # ' + IntToStr(I) + ' you may spend R' + IntToStr(Prize);
      lstNumber.Items.Add(ListItems);
    end;
    
    Cost := 'Total prize value : R' + IntToStr(TotalCost);
    lstNumber.Items.Add(Cost);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone please help. I have a problem where I need to loop through
I need to display a google map with several markers. The problem I have
I have a simple problem regarding a loop in a Rails controller. Here's the
I have a problem with a continue statement in my C# Foreach loop. I
I have an interesting problem. I wrote the following perl script to recursively loop
I have a coding/maths problem that I need help translating into C#. It's a
I have a loop problem. I want to collect name counts for each items
Problem: I have a string of numbers, lets call it strNumbers. I need to
Really hope this can be done but I have come across a problem I
Problem: I need to output the TOP X Contributors determined by the amount of

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.