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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:50:40+00:00 2026-06-12T21:50:40+00:00

I am having a problem with the program I am trying to code. It’s

  • 0

I am having a problem with the program I am trying to code. It’s just a Windows console program and I am very new to C++. It’s only my 4th program.

The problem I am having is that when I run my program I have no errors but a lot of warnings that say “comparison with string literal results in unspecified behaviour” in the lines that I will highlight below.

When the program runs instead of adding the numbers I want it to it just gives me a random huge number no matter what I put in for my inputs.

Here is the code:

#include <iostream>

using namespace std;

int main()
{
     int hold;
     int i;
     int n;
     i = 6;
     int result;
     int * price;
     char items[100][100];

     if (items == 0)
        cout << "No items can be stored";
    else
    {
        for (n=0; n<i; n++)
        {
            cout << "Item#" << n << ": ";
            cin >> items[n];
        }
        cout <<  "\nYou Entered: \n";
        for (n=0; n<i; n++)
            cout << items[n] << ", ";

    }
    for (n=0; n<i; n++)
    {
        if (items[n] == "ab"){
        price[n] = 2650;
        }

        else if (items[n] == "ae"){
        price[n] = 1925;
        }

        else if (items[n] == "ie"){
        price[n] = 3850;
        }

        else if (items[n] == "bt"){
        price[n] = 3000;
        }

        else if (items[n] == "pd"){
        price[n] = 2850;
        }

        else if (items[n] == "ga"){
        price[n] = 2600;
        }

    }

    for (n=0; n<i; n++)
    {
    result = result + price[n];
    }

    cout << "\nTotal gold for this build: " << result;
    cin >> hold;
    return 0;
}

Any help is appreciated. There is probably something big that I’ve done wrong. The names in the if statements are all currently placeholders and I’ll be adding a lot more if statements when I can get it to work with the bare 6 which is what it needs to work.

  • 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-12T21:50:41+00:00Added an answer on June 12, 2026 at 9:50 pm

    In C++ == only implemented internally for primitive types and array is not a primitive type, so comparing char[100] and string literal will only compare them as 2 char* or better to say as 2 pointers and since this 2 pointers can’t be equal then items[n] == "ae" can never be true, instead of this you should either use std::string to hold string as:

    std::string items[100];
    // initialize items
    if( items[n] == "ae" ) ...
    

    or you should use strcmp to compare strings, but remeber strcmp return 0 for equal strings, so your code will be as:

    char items[100][100];
    // initialize items
    if( strcmp(items[n], "ae") == 0 ) ...
    

    And one extra note is if (items == 0) is useless, since items allocated on stack and not in the heap!

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

Sidebar

Related Questions

I'm having a very strange problem when trying to run RapidXml 1.13 under Windows
Im having a very odd problem. Im trying to install a Python program. Im
I've run into a very annoying problem while trying to update some code. The
I'm having problem when running my Windows Forms program. In the program, I have
I'm having a very odd problem with my program and am hoping you can
I'm having a bit of a problem with this code. The program gives me
I have started learning Java and am having problem with a simple program that
Having some problem getting my program to sleep What im trying to do is
Ok, so I'm having a problem trying figure out the problem in my code.
I'm having a problem with some code in Visual C++ 2010 Express. I'm trying

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.