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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:04:57+00:00 2026-05-31T12:04:57+00:00

Basically, the program is asking for a user entered product name which will be

  • 0

Basically, the program is asking for a user entered product name which will be entered into a structure. However, if the name entered is “quit” (without the quotes) the loop should terminate. Here is the complete code:

#include <iostream>
#define maxNum 9
using namespace std;

struct Products{
       char name [20];
       int modelNumber;
       float price;
       } products [maxNum];

void productsDisplay (Products products);

int main()
{
    int i;
    int k;
    cout << "Enter up to 10 product details.\n"
         << "Enter quit as product name to exit the program.\n";

         for (i = 0; i <= maxNum; i++)
         {
              cout << "Enter the product name: ";
              cin >> products[i].name;
              if (products[i].name == "quit")
                 break;
              cout << "Enter the model number: ";
              cin >> products[i].modelNumber;
              cout << "Enter the price: ";
              cin >> products[i].price;
              cout << endl;
          }

    for (k = 0; k <= i; k++)
    {
        productsDisplay (products[k]);
    }

    system("pause");
    return 0;
}

void productsDisplay (Products products)
{
     cout << "Product name: " << products.name << endl;
     cout << "Model number: " << products.modelNumber << endl;
     cout << "Product price: $" << products.price << endl;
     cout << "----------------------\n";
} 

The main problem is this bit:

 for (i = 0; i <= maxNum; i++)
             {
                  cout << "Enter the product name: ";
                  cin >> products[i].name;
                  if (products[i].name == "quit")
                     break;

Everything actually works fine except when I enter “quit” the program doesn’t break from the for loop and continues until it is finished. The solution probably lies with using string-type instead and the “strcopy” statement but I’m not too sure how to implement them correctly. I’m quite stumped over this problem and would appreciate any assistance on fixing it, thanks for reading.

  • 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-31T12:04:58+00:00Added an answer on May 31, 2026 at 12:04 pm

    The comparison

    products[i].name == "quit"
    

    is wrong.

    You need to use strcmp (or strncmp, as Vaibhav pointed out):

    if ( strcmp(products[i].name,"quit") == 0 ) //0 indicates equality
          break;
    

    But since this is C++, I suggest you use std::string instead of char[].

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

Sidebar

Related Questions

Basically I want to make simple toggle program (that will be mapped to some
i am creating a bluetooth based server program in Bluez which basically handles connections
There is a LEDA program. http://www.algorithmic-solutions.com/ which basically provides GUI to algorithms. I d
Basically the program takes customer information and dumps it in a database. In order
I am using a facade design pattern for a C# program. The program basically
Right what im trying to accomplish is a program that basically sets the active
Basically, I want to have my program retrieve various variables from the hard drive
Basically, is it possible to identify if some-one hooks up my program to SQL
I have a Java program that generates Java classes for my application. Basically it
I wrote a small program to test accessing a widget parent's slot. Basically, it

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.