• What do you need help with? V. 3.0
    4,884 replies, posted
Assuming the user doesn't type a %, you can just read a normal int, then divide by 100 to get a float (or double) between 0 and 1. 50% = 0.5 etc. [editline]5th October 2011[/editline] Oh and you can't write conditions like that, you have to write them like this: [code]if ((number1 > number2) && (number1 > number3)) ...[/code]
[QUOTE=thomasfn;32639763]Assuming the user doesn't type a %, you can just read a normal int, then divide by 100 to get a float (or double) between 0 and 1. 50% = 0.5 etc. [editline]5th October 2011[/editline] Oh and you can't write conditions like that, you have to write them like this: [code]if ((number1 > number2) && (number1 > number3)) ...[/code][/QUOTE] i didnt really understand the first part :S [QUOTE] cout << "Input amount: "; cin >> number1; cout << "Input VAT rate: "; cin >> number2; cout << "VAT cost/amount/whateveritscalled: " << number1 * number2 << endl;[/QUOTE] this is what the last part of the program looks like. if i put a % number in the VAT thingy, it just multiplies it as if it were a regular number
[QUOTE=Clio;32640305]i didnt really understand the first part :S this is what the last part of the program looks like. if i put a % number in the VAT thingy, it just multiplies it as if it were a regular number[/QUOTE] If you want to multiply something by 50%, you'd multiply it by 0.5, right? If you wanted to multiply it by 20%, it'd be 0.2, right? So it goes like this: [code]number1 * (number2 / 100)[/code]
now it just = 0, it doesnt matter what i input on the things :S oh wait i changed the wrong int to float xD it works now thanks
[QUOTE=Clio;32640989]now it just = 0, it doesnt matter what i input on the things :S[/QUOTE] It sounds like you're dividing integers. You to cast to float before division.
I think when dividing, it works with the type on the right side. So try this: [code]number1 * (number2 / 100.0)[/code]
How would I go about writing a parser for a textbased game in C++? I've got the string tokenizing working but what would be the best way to actually parse what the player inputs? [editline]5th October 2011[/editline] What I have now would just keep expanding to an enormous tree of if and else if cases.
[QUOTE=thomasfn;32641317]I think when dividing, it works with the type on the right side. So try this: [code]number1 * (number2 / 100.0)[/code][/QUOTE] Actually, it favors promotion to demotion, so if you have a float and an integer, it's going to promote the integer to a float. If you have a long int and a short int, it's going to promote the short int to a long int.
Basically what i'm doing is a task where i'm supposed to make a codelock that unlocks only for the number "2417". what i have is this to work with. The assignment is in VHDL [quote]library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; entity codelock is port( clk: in std_logic; K: in std_logic_vector(1 to 3); R: in std_logic_vector(1 to 4); q: out std_logic_vector(4 downto 0); UNLOCK: out std_logic ); end codelock; architecture behavior of codelock is subtype state_type is integer range 0 to 31; signal state, nextstate: state_type; begin nextstate_decoder: -- next state decoding part process(state, K, R) begin case state is when 0 => if (K = "001" and R ="0001") then nextstate <= 1; else nextstate <= 0; end if; when 1 => if (K = "001" and R ="0001") then nextstate <= 1; elsif (K = "000" and R = "0000") then nextstate <= 2; else nextstate <= 0; end if; when 2 to 30 => nextstate <= state + 1; when 31 => nextstate <= 0; end case; end process; debug_output: -- display the state q <= conv_std_logic_vector(state,5); output_decoder: -- output decoder part process(state) begin case state is when 0 to 1 => UNLOCK <= '0'; when 2 to 31 => UNLOCK <= '1'; end case; end process; state_register: -- the state register part (the flipflops) process(clk) begin if rising_edge(clk) then state <= nextstate; end if; end process; end behavior; [/quote] How am i supposed to remake the K and R values?! i don't even know which string i'm supposed to start with! Whoever helps me out is a great man!
[QUOTE=Armandur;32641533]How would I go about writing a parser for a textbased game in C++? I've got the string tokenizing working but what would be the best way to actually parse what the player inputs? [editline]5th October 2011[/editline] What I have now would just keep expanding to an enormous tree of if and else if cases.[/QUOTE] I was just writing out the basic layout of a text-based role playing/simulation/strategy game and realized that i'm going to have an ass-load of if..else if statements. Double appreciation for anyone that helps :D
Is there a tutorial anywhere on how to find what vertex from an array of vertices is under the cursor in XNA 4?
[QUOTE=Wyzard;32636561]What you'd need to do is: * Convert the character to uppercase using toupper() (#include <cctype> for this). Making everything the same case simplifies the steps that follow, and the cipher would be less effective if it didn't conceal capitalization anyway. * Check that the character is actually a letter. If it's less than 'A' or greater than 'Z', pass it through unchanged or abort with an error message or something. The reason for doing this [i]after[/i] calling toupper() is that now you don't have to include lowercase letters in the range you check against. And toupper() passes non-letters through unchanged. * Subtract 'A' from the letter to get its position in the alphabet. That is, 'A' becomes 0, 'B' becomes 1, and so on. * Add your "key" number, and take the result modulo 26. That's done with the modulus operator, %, which makes things "wrap around" to zero if they go past the maximum you specify: 25 % 26 == 25, 26 % 26 == 0, 27 % 26 == 1, and so on. Rather than hard-coding the number 26 in your program, it'd be better to write something like (('Z' - 'A') + 1). * Add 'A' to convert the modified alphabet position back into an actual letter. 0 becomes 'A', 1 becomes 'B', and so on.[/QUOTE] [CODE]#include <cctype> #include <iostream> #include <sstream> #include <string> using namespace std; int main() { string userText,shiftHold; int shifts,userTextPos; enter_text:cout<<"Enter some text to encrypt: "<<endl; getline(cin,userText); cout<<endl; char *Alphabet[26]; Alphabet[0]="A"; Alphabet[1]="B"; Alphabet[2]="C"; Alphabet[3]="D"; Alphabet[4]="E"; Alphabet[5]="F"; Alphabet[6]="G"; Alphabet[7]="H"; Alphabet[8]="I"; Alphabet[9]="J"; Alphabet[10]="K"; Alphabet[11]="L"; Alphabet[12]="M"; Alphabet[13]="N"; Alphabet[14]="O"; Alphabet[15]="P"; Alphabet[16]="Q"; Alphabet[17]="R"; Alphabet[18]="S"; Alphabet[19]="T"; Alphabet[20]="U"; Alphabet[21]="V"; Alphabet[22]="W"; Alphabet[23]="Y"; Alphabet[24]="X"; Alphabet[25]="Z"; enter_shifts:cout<<"Enter a number between 1 and 26: "<<endl; getline(cin, shiftHold); stringstream(shiftHold)>>shifts; cout<<endl; if (shifts>=1 && shifts<=26) { for (int userTextPos=0;userTextPos<userText.size();userTextPos++) { char indChar=userText[userTextPos]; indChar=toupper(indChar); if(isalpha(indChar)) { //Need to do something along the lines of "if indChar="A" then indChar=Alphabet[0] and so on so that I can add "shifts" to Alphabet[indChar] } else; cout<<"Slot "<<userTextPos<<": "<<indChar<<endl; } } else { goto enter_shifts; } char cont; cout<<endl<<"Press any key and enter to continue..."<<endl; cin>>cont; return 0; }[/CODE] Is there a way to check if what letter indChar is and assign it to Alphabet[indChar] accordingly? I guess I could just write out a bunch of if..else if statements but I'm almost positive there is a simpler way. Oh btw, I need to assign Alphabet[indChar] to indChar in order to add 'shifts' to Alphabet[indChar] for the actual method of encryption. Sorry for the overuse of the goto statement, I've noticed some people on this forum dislike it :v:
[QUOTE=Jacen;32648075]Is there a tutorial anywhere on how to find what vertex from an array of vertices is under the cursor in XNA 4?[/QUOTE] if your vertices are defined in window coordinates (same as your cursor) just iterate through the vertices until you find one that's under your cursor. If they're inside a projection with some arbitrary scale, you'll have to [url=http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.viewport.unproject.aspx]unproject[/url] the cursor location and then check that position against all the vertices.
[QUOTE=robmaister12;32649351]if your vertices are defined in window coordinates (same as your cursor) just iterate through the vertices until you find one that's under your cursor. If they're inside a projection with some arbitrary scale, you'll have to [url=http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.viewport.unproject.aspx]unproject[/url] the cursor location and then check that position against all the vertices.[/QUOTE] Thanks.
[QUOTE=DeltaSmash;32649121][CODE]#include <cctype> #include <iostream> #include <sstream> #include <string> using namespace std; int main() { string userText,shiftHold; int shifts,userTextPos; enter_text:cout<<"Enter some text to encrypt: "<<endl; getline(cin,userText); cout<<endl; char *Alphabet[26]; ---snip--- enter_shifts:cout<<"Enter a number between 1 and 26: "<<endl; getline(cin, shiftHold); stringstream(shiftHold)>>shifts; cout<<endl; if (shifts>=1 && shifts<=26) { for (int userTextPos=0;userTextPos<userText.size();userTextPos++) { char indChar=userText[userTextPos]; indChar=toupper(indChar); if(isalpha(indChar)) { //Need to do something along the lines of "if indChar="A" then indChar=Alphabet[0] and so on so that I can add "shifts" to Alphabet[indChar] } else; cout<<"Slot "<<userTextPos<<": "<<indChar<<endl; } } else { goto enter_shifts; } char cont; cout<<endl<<"Press any key and enter to continue..."<<endl; cin>>cont; return 0; }[/CODE] Is there a way to check if what letter indChar is and assign it to Alphabet[indChar] accordingly? I guess I could just write out a bunch of if..else if statements but I'm almost positive there is a simpler way. Oh btw, I need to assign Alphabet[indChar] to indChar in order to add 'shifts' to Alphabet[indChar] for the actual method of encryption. Sorry for the overuse of the goto statement, I've noticed some people on this forum dislike it :v:[/QUOTE] You could also use std::string for alphabet: string alphabet = "ABC...YXZ";
[QUOTE=DeltaSmash;32649121]Is there a way to check if what letter indChar is and assign it to Alphabet[indChar] accordingly? I guess I could just write out a bunch of if..else if statements but I'm almost positive there is a simpler way. Oh btw, I need to assign Alphabet[indChar] to indChar in order to add 'shifts' to Alphabet[indChar] for the actual method of encryption. Sorry for the overuse of the goto statement, I've noticed some people on this forum dislike it :v:[/QUOTE] You can also use [url]http://www.asciitable.com/[/url] and check the decimal range for the characters a - z, which is 97 to 122. If you want it in 0 - 25 range, just do minus 97 on the character.
Heyy im using c# and i have and XML file which im putting in a list box how do i put the xml name node in an array and sort them alphabetically or is there another way to sort a list box ?
I need to sort out a decent tile-based collision system for a top-down shooter. Here's my code at the moment: [code]for (int i = 0; i < MapManager.solids.size(); i++) if (MapManager.solids.get(i).boundingBox.intersects(boundingBox)) movement.set(0, 0); position.add(movement.scale(speed));[/code] But my dudes get stuck on walls. Ideally they'd slide along them.
Should I have my particle manager manage particles, or particle spawners?
Particle spawners, more flexible and makes more sense.
Alright, so I just converted a crapton of stuff in my game engine from raw file paths to 'resource ids' (basically a case-insensitive hash of a virtual file path) and tweaked my resource caching system so that it maintains a centralized list of files instead of having different resource caches for each type. Now what it does is it builds a list of files with their real paths and creates a 'virtual' path to generate the resource id. The general idea was to abstract resources from the underlying file system so that I could add a PK3/GCF or similar compressed archive file system later. Now I was hoping that this was just going to kind of work, but it turns out this is completely incompatible with my current materials system. The 'raw' materials format I use is just the base path for four textures containing albedo, specular, normal, and emissive data. This works perfectly fine, as the materials actually have real files on the hard disk. What doesn't work, however, is Wavefront material template libraries. I kinda had these kludged in there so that you would 'set' the current library, and then all the materials within that library would be accessible through the resource system as if they were files. That doesn't work anymore because resource paths can no longer be specified dynamically. A list of valid files needs to be presented to the resource system before they can be accessed. It just seems so sloppy to create/destroy entries every time the MTL file is changed. I'm actually really hating the whole idea of MTL files at the moment, even moreso than when I was trying to shoehorn them in the first time.
Is it possible to put a XNA window in a Windows Form? I have a feeling that would be a better idea for a world editor.
[QUOTE=Jacen;32659603]Is it possible to put a XNA window in a Windows Form? I have a feeling that would be a better idea for a world editor.[/QUOTE] [url=http://forums.create.msdn.com/forums/p/6471/34180.aspx#34180]Very much yes[/url]. My friend set it up in our project so we could use the Windows WM_CHAR message.
[QUOTE=foszor;32659771][url=http://forums.create.msdn.com/forums/p/6471/34180.aspx#34180]Very much yes[/url]. My friend set it up in our project so we could use the Windows WM_CHAR message.[/QUOTE] Thank you.
So I got a problem with my particles. I am using a pointer to an array. [cpp]cparticle particles *; particles = new cparticles[amount]//this is int he initialization once I know how many particles are needed [/cpp] I access them like this: particles[amount] (amount being any particle in question); However, the debugger says that "Windows has triggered a breakpoint in SFML Game.exe. This may be due to a corruption of the heap, which indicates a bug in SFML Game.exe or any of the DLLs it has loaded." I am not sure what I am doing wrong here. Is there a special way to treat pointers to heap arrays?
I'm guessing the asterisk after the name is just a typing error. Try poking the debugger to tell you where that supposed corruption takes place.
Woops I meant to say cparticle * particles. The problem is that I have to run in release because boost doesn't function well with visual studio 2010.
You can also debug release builds .. they don't contain as much information, but the debugger can still pick up on stuff.
So I keep getting an error saying: "syntax error : identifier 'gameManager'" In this code which I'm using menu.h: [code]#ifndef m_h #define m_h #include <SFML/Window.hpp> #include <SFML/Graphics.hpp> #include "gameManager.h" class mainMenu { //Resources sf::RenderWindow *App; sf::Text btnNew; sf::Text btnQuit; sf::Image bgImage; sf::Sprite bgSprite; sf::Mouse *mouse; int commandThrowback; bool shouldDraw; void draw(); public: mainMenu(gameManager *gm); <--- Error! void update(); int getCommand(); }; #endif[/code] Now I can only see one reason why I would be getting this and that would be if I didn't define gameManager(duh) but as you can see I've included "gameManager.h" which is this file: [code]#ifndef gm_h #define gm_h #include <SFML/Window.hpp> #include <SFML/Graphics.hpp> #include "menu.h" class gameManager { //General Resources sf::RenderWindow *App; sf::Mouse mouse; int state; int WIDTH; int HEIGHT; void executeCommand(int cmd); public: gameManager(sf::RenderWindow *new_App); sf::Vector2i getScreenSize(); sf::RenderWindow* getRenderWindow(); sf::Mouse* getMouse(); void update(); }; #endif[/code] I'm at a loss here, anyone know what stupid thing I've done wrong?
You have a circular include.
Sorry, you need to Log In to post a reply to this thread.