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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:55:07+00:00 2026-05-29T14:55:07+00:00

I have been trying to write some code that asks the user for several

  • 0

I have been trying to write some code that asks the user for several debit entries for an accounting program. If the user gives 5 as the answer, the program should ask him the debit entry’s name and amount 5 times before continuing on to the next line of code. So, I used for loops to solve this problem and it seems something strange is happening.

This is the format in which the code should run when being compiled and executed:

How many debit entries do you wish to make?: 2
1. Debit Entry Name: example1
1. Debit Amount: 123
2. Debit Entry Name: example2
2. Debit Amount: 456

continue on to next line of code

Here’s the code I’ve written in C++ for this part of the accounting program:

#include <iostream>
#include <string>
using namespace std;

int main()
{
   cout << "How many debit entries do you wish to make?: ";
   int entries;
   cin >> entries;
   string debitNames[50];
   float debitAmounts[50];
   int offset = 0;
   int number = 1;
   for (offset = 0; offset < entries; offset++)
   {
      cout << number << ". Debit Entry Name: ";
      cin >> debitNames[offset];
      cout << number << ". Debit Amount: ";
      cin >> debitAmounts[offset];
      for (number = 1; number <= entries; number++)
      {
      }
   }
   char response;
   cin >> response;
   return 0;
}

The outcome is extremely strange, here is what happens when I compile and run it:

How many debit entries to do you wish to make?: 5
1. Debit Entry Name: example1
1. Debit Amount: 123
6. Debit Entry Name: example2
6. Debit Amount : 123
6. Debit Entry Name: example3
6. Debit Amount: 123
6. Debit Entry Name: example4
6. Debit Amount: 123
6. Debit Entry Name: example5
6. Debit Amount: 123

continue on to next line of code

The program, after listing the number as 1, suddenly jumps off to 6 and remains there until all the 5 sets of questions have been asked. As you know by now I’m using the ‘number’ variable to simply tell the user that ‘number’ entries have been asked, as specified by the user his/herself. Try running this code in your compiler and see whether the same result appears. By the way, I use Visual C++ 20120 Express Edition, could this have anything do with the problem?

Thanks a lot.

  • 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-29T14:55:08+00:00Added an answer on May 29, 2026 at 2:55 pm

    Well, before the loop, you set the number variable to 1.

    Inside the loop, you set the number variable to (entries + 1) using this snippet:

    for (number = 1; number <= entries; number++)
    {
    }
    

    Why not simply do this?

    cout << (offset + 1) << ". Debit Entry Name: ";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to write a regex that will remove whitespace following a
I'm trying to write some jQuery code that gets the combined width of images
I have been writing some code that creates a generic blog. Its features are
I am trying to read some code that I did not write. In the
I'm trying to write some code that allows me to switch between SQLCE (locally
I'm trying to write some code that will render a texture onto a simple
I have recently been trying ot write code to add and delete content form
I have been trying to figure out how to write a simple program to
I've been trying to write Jquery code to check if two inputs have the
I cannot write Javascript code yet, and I'm trying to edit some code that

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.