Thread: vveapon costs

  1. #1
    Registered User
    Join Date
    Dec 2017
    Posts
    37

    vveapon costs

    hovv do i put 1000 dollars and hovv can i make the vveapons cost things
    Code:
    #include "stdafx.h"
    using namespace std;
    #include <iostream>
    #include <vector>
    #include <string>
    
    int main()
    {
        
    
    
        vector<string> weapons =
        {
            "banana bomb","grenade","bazooka","uzi","shotgun","air strike"
        };
        
        cout << weapons[0] << endl;
    
        return 0;
    }

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Dude... you ain't funny. Try harder!
    Devoted my life to programming...

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Not vv

    Not even
    vveapon costs-74ea5a673de67310325c4ec28c4c354c-star-wars-imdb-starship-troopers-jpg

    But THIS
    vveapon costs-w-key-png

    You can obviously use it in your code, so why not in your prose?!
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    My guess is that you just need a way to store a relationship between the price and a weapon. Use a map. If I were going to build a class for the weapons shop, I might use this constructor:
    Code:
    #include <string>
    #include <vector>
    #include <map>
    #include <random>
    using namespace std;
    
        WeaponsShop(const int min = 200, const int max = 10000)
        {
            vector<string> weapons =
            {
                "banana bomb","grenade","bazooka","uzi","shotgun","air strike"
            };
            default_random_engine rng;
            uniform_int_distribution<int> d(min, max);
            for (string key : weapons)
            {
                shelf[key] = d(rng) / 10 * 10; // random price, truncated by 10 of whatever currency
            }
        }
    Or a vector of pairs. That's a start.
    Last edited by whiteflags; 12-20-2017 at 11:49 AM.

  5. #5
    Registered User
    Join Date
    Jun 2017
    Posts
    157
    Why don't you use a struct as I recommended in your other thread?
    creating a store

  6. #6
    Registered User
    Join Date
    Dec 2017
    Posts
    37
    hovv do i make the banana bomb cost 400 gold grenade 500 gold bazooka 700 gold uzi 900 gold shotgun 1100 gold and air strike 1500 gold and hovv can i store the gold (like 2500 - 1500 = 1000)

    Code:
    #include "stdafx.h"
    #include <string>
    #include <vector>
    #include <iostream>
    using namespace std;
     
    int gold;
    
    int main()
    {
        cout << "You have 2500 gold" << endl;
        
        vector<string> weapons =
        {
            "banana bomb","grenade","bazooka","uzi","shotgun","air strike"
        };
        
        
    
        return 0;
    }

  7. #7
    Registered User
    Join Date
    Dec 2017
    Posts
    37
    hovv do you shovv the prices of the vveapons sorry
    Code:
    #include <vector>
    #include <iostream>
    using namespace std;
     
    void main()
    {
        cout << "\nYou have 2500 gold" << endl;
        
        vector<string> weapons =
        {
            "banana bomb","grenade","bazooka","uzi","shotgun","air strike"
        };
        
    
    }
    
        class MyClass {
        public:
            MyClass()
            {
                cout << "Buy a weapon?";
            }
        } m;

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Can't tell if this is illiteracy, or ancient Roman hipsterism.

    Or just plain putting the Duh in inDUHvidualism.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by OldGuy2 View Post
    Why don't you use a struct as I recommended in your other thread?
    creating a store


    Structures in C and C++ - Tutorial - Cprogramming.com
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Distributed VC with small entry costs
    By Mario F. in forum General Discussions
    Replies: 8
    Last Post: 06-20-2011, 04:23 AM
  2. Software Development. Other costs.
    By Mario F. in forum General Discussions
    Replies: 5
    Last Post: 10-24-2009, 11:34 PM

Tags for this Thread