• What do you need help with? Version 5
    5,752 replies, posted
[QUOTE=Asgard;39457965][url]https://gist.github.com/97ace9631273fd37646d[/url] Anyone know what's wrong?[/QUOTE] put [cpp] MenuState MenuState::_menuState; [/cpp] after #include "menustate.h" [editline]3rd February 2013[/editline] it's not what you're asking about but on main.cpp:10 you're implicitly casting from "const char*" to "char*" with a string literal - that's not good as it will most likely be read-only memory and the function may try to write to it. this will cause a crash. if it's your own function function you're calling, change the signature to "const char*".
[QUOTE=mechanarchy;39458043]put MenuState MenuState::_menuState; after #include "menustate.h" [editline]3rd February 2013[/editline] it's not what you're asking about but on main.cpp:10 you're implicitly casting from "const char*" to "char*" with a string literal - that's not good as it will most likely be read-only memory and the function may try to write to it. this will cause a crash. if it's your own function function you're calling, change the signature to "const char*".[/QUOTE] Thank you very much!
It's me again, sorry for bothering but i have another problem that i have to face. the part of the code goes like this: [code] while(true){ for(int i=0; i<Name.length; i++){ for(int j=0; j<i; j++){ System.out.print("Vnesite ime: "); Name[i] = scan.nextLine(); if(!(Name[i].equals(Name[j]))){ ...[/code] It all compiles and that's great, but when i run the program, the part where it should scan for Name[i](first time), it just fills in the name itself(blank) and then jumps over to the next scan further in the program
[QUOTE=RandomDexter;39458954]It's me again, sorry for bothering but i have another problem that i have to face. the part of the code goes like this: [code] while(true) { for(int i = 0; i < Name.length; i++) { for(int j = 0; j < i; j++) { System.out.print("Vnesite ime: "); Name[i] = scan.nextLine(); if(!(Name[i].equals(Name[j]))) { ...[/code] It all compiles and that's great, but when i run the program, the part where it should scan for Name[i](first time), it just fills in the name itself(blank) and then jumps over to the next scan further in the program[/QUOTE] Why are you using three loops to do one thing? Also spaces mate, use them :/
[QUOTE=mobrockers2;39459211]Why are you using three loops to do one thing? Also spaces mate, use them :/[/QUOTE] i have to write a phone book where the user states the maximum capacity, then he inserts names, and if the name hasn't been used yet, then he has to insert the phonenumber too, else the name and the number outprints. i used for(int j = 0; j < i; j++) so the program can check if the name is already in the "Name" array, but it's obviously not working out :( Sorry :P
Nevermind, I fixed the problem!
[QUOTE=RandomDexter;39459290]i have to write a phone book where the user states the maximum capacity, then he inserts names, and if the name hasn't been used yet, then he has to insert the phonenumber too, else the name and the number outprints. i used for(int j = 0; j < i; j++) so the program can check if the name is already in the "Name" array, but it's obviously not working out :( Sorry :P[/QUOTE] -snip did a goof-
[QUOTE=RandomDexter;39459290]i have to write a phone book where the user states the maximum capacity, then he inserts names, and if the name hasn't been used yet, then he has to insert the phonenumber too, else the name and the number outprints. i used for(int j = 0; j < i; j++) so the program can check if the name is already in the "Name" array, but it's obviously not working out :( Sorry :P[/QUOTE] you're structuring your loops improperly. you'll still need 3 loops to get the desired behaviour, but formatted like so [code] for i=0 to number of entries: while true: read name[i] for j = 0 to i if name[j] == name[i] // name used, ask for name again // name not already used, go to next i [/code]
[QUOTE=mechanarchy;39459451]you're structuring your loops improperly. you'll still need 3 loops to get the desired behaviour, but formatted like so [code] for i=0 to number of entries: while true: read name[i] for j = 0 to i if name[j] == name[i] // name used, ask for name again // name not already used, go to next i [/code][/QUOTE] Huh, wouldn't this just get stuck at i = 0, since it goes through the for loop, sets i = 0, enters the while and never goes back to the original for.
[QUOTE=eternalflamez;39459502]Huh, wouldn't this just get stuck at i = 0, since it goes through the for loop, sets i = 0, enters the while and never goes back to the original for.[/QUOTE] i didn't really want to give too much away as it seems to be a homework problem, but you'll need to use a break statement to get out of the 'while true' loop and back into the 'for i' loop; but only once you've made sure the entered name is unique. [editline]4th February 2013[/editline] my pseudocode is missing a fair bit of flow control
This is what i have so far [URL="http://pastebin.com/w9TKSJZK"]http://pastebin.com/w9TKSJZK[/URL], but it's got bugs all over the place :S If i(the user) insert the same name twice, the program doesn't outprint the necessary. Sorry for readability [B]Edited[/B] Instruction: i have to write a phone book where the user states the maximum capacity, then he inserts names, and if the name hasn't been used yet, then he has to insert the phonenumber too, else the name and the number outprints. If phonebook is already full, it still demands the name, but the message:"phonebook is full" outprints, the programm ends, when the user inserts "0" as the name.
Not exactly a programming question per se, but i was making a simple sidescroller game in C# using XNA and a free 2d physics engine. Since XNA is being dropped i figure i might as well abandon ship since i didn't have much completed anyhow. What would be a good alternative? I've been eyeing up C++ and SFML, but there's also monogame which could be an interesting alternative to XNA. Thoughts?
c++ and sfml is very easy to use
I'm about ready to give up on SDL_ttf My CMakeLists.txt file: [URL]https://gist.github.com/875d5d1ead3a109cdc22[/URL] [code]$ cmake . 2.0.12 -- REQUIRED_VARS -- Found SDL2: /usr/lib/libSDL2main.a;/usr/lib/libSDL2.so;-lpthread /usr/local/include/SDL /usr/lib/x86_64-linux-gnu/libSDL_ttf.so /usr/include/SDL2 /usr/lib/libSDL2main.a/usr/lib/libSDL2.so-lpthread -- Configuring done -- Generating done -- Build files have been written to: /home/asgard/projects/SDL_dungeon[/code] This shows to me that it can find the libraries and include directories just fine. So, why is it that it still throws the following error: [code]undefined reference to `TTF_OpenFont'[/code]
Holy fuck I've got it down to only two errors. Menu.h [cpp]#include <SFML/Window.hpp> #include <SFML/Graphics.hpp> #include <Source/Text/Text.h> #include <list> class Menu { public: ... struct MenuItem { public: Text text; sf::FloatRect buttonrect; static void highlightRectOutline(sf::RenderWindow &window, sf::Color color); MenuResult action; };[/cpp] My errors: [cpp]Error 1 error C2146: syntax error : missing ';' before identifier 'text' ( Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [/cpp] The error is occuring on the line Text text;
Well, there's nothing wrong in the code you show there, so it's either something wrong in the "Source/Text/Text.h" file or there's something wrong in the rest of the code you left out.
Text.h [cpp]#include <SFML/Window.hpp> #include <SFML/Graphics.hpp> enum style { bold, italic, underlined }; class Text { public: void create(sf::RenderWindow &window, char* string, char* fontpath, float positionx, float positiony, unsigned int size, style textstyle, sf::Color color); sf::FloatRect getRect(); static float getHeight(); static float getWidth(); bool operator==(Text t); bool operator!=(Text t); void setString(sf::RenderWindow &window, char* string); sf::String getString(); void setFont(sf::RenderWindow &window, char* fontpath); sf::Font getFont(); void setPosition(sf::RenderWindow &window, float x, float y); static sf::Vector2f getPosition(); void setScale(sf::RenderWindow &window, float x, float y); sf::Vector2f getScale(); void setColor(sf::RenderWindow &window, int red, int green, int blue, int alpha); sf::Vector3i getColor(); private: static sf::Text text; sf::Font font; };[/cpp] [editline]3rd February 2013[/editline] [QUOTE=Meatpuppet;39462870]Holy fuck I've got it down to only two errors. Menu.h [cpp]#include <SFML/Window.hpp> #include <SFML/Graphics.hpp> #include <Source/Text/Text.h> #include <list> class Menu { public: ... struct MenuItem { public: Text text; sf::FloatRect buttonrect; static void highlightRectOutline(sf::RenderWindow &window, sf::Color color); MenuResult action; };[/cpp] My errors: [cpp]Error 1 error C2146: syntax error : missing ';' before identifier 'text' ( Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [/cpp] The error is occuring on the line Text text;[/QUOTE]
[QUOTE=Asgard;39461769]I'm about ready to give up on SDL_ttf My CMakeLists.txt file: [URL]https://gist.github.com/875d5d1ead3a109cdc22[/URL] [code]$ cmake . 2.0.12 -- REQUIRED_VARS -- Found SDL2: /usr/lib/libSDL2main.a;/usr/lib/libSDL2.so;-lpthread /usr/local/include/SDL /usr/lib/x86_64-linux-gnu/libSDL_ttf.so /usr/include/SDL2 /usr/lib/libSDL2main.a/usr/lib/libSDL2.so-lpthread -- Configuring done -- Generating done -- Build files have been written to: /home/asgard/projects/SDL_dungeon[/code] This shows to me that it can find the libraries and include directories just fine. So, why is it that it still throws the following error: [code]undefined reference to `TTF_OpenFont'[/code][/QUOTE] I've looked through the entire $ cmake --trace output, and I am sure everything is found and linked correctly. What is going wrong? [editline]3rd February 2013[/editline] objdump just informed me that the architecture of the .so files are exactly the same, so it most likely isn't that either. I'm about ready to kill myself.
[QUOTE=Meatpuppet;39463101]Text.h[/QUOTE] You haven't wrapped it with a header file define, it might be shitting itself if you're including it more than once. [cpp] #ifndef TEXT_H #define TEXT_H ... #endif [/cpp]
[QUOTE=ief014;39464244]You haven't wrapped it with a header file define. [cpp] #ifndef TEXT_H #define TEXT_H ... #endif [/cpp][/QUOTE] This is known as an "include guard".
[QUOTE=ief014;39464244]You haven't wrapped it with a header file define, it might be shitting itself if you're including it more than once. [cpp] #ifndef TEXT_H #define TEXT_H ... #endif [/cpp][/QUOTE] I'm using #pragma once; for some reason that didn't paste in the code.
[QUOTE=Meatpuppet;39464267]I'm using #pragma once; for some reason that didn't paste in the code.[/QUOTE] Then, what are you leaving out in the Menu.h file? It might be something that you excluded from your posted code that's causing the issue. [QUOTE=esalaka;39464247]This is known as an "include guard".[/QUOTE] That's it, I was trying to think up of a name :P
I'm doing that in both files. That's weird, ctrl+a has failed me :(
[QUOTE=Meatpuppet;39464267]I'm using #pragma once; for some reason that didn't paste in the code.[/QUOTE] It's just #pragma once no semicolon
that was a grammar semicolon
[QUOTE=Meatpuppet;39464452]that was a grammar semicolon[/QUOTE] I wasn't sure if it was that so I decided to mention it
omfg i'm so CLOSE to getting this to work
[QUOTE=Meatpuppet;39464509]omfg i'm so CLOSE to getting this to work[/QUOTE] ... [QUOTE=ief014;39464302]Then, what are you leaving out in the Menu.h file? It might be something that you excluded from your posted code that's causing the issue.[/QUOTE]
full menu.h for ief014 [cpp]#pragma once #include <Source/Text/Text.h> #include <list> class Menu { public: static enum MenuResult { Exit, Options, Back, ChangeResolution, Play, Nothing }; MenuResult showMMenu(sf::RenderWindow &window); MenuResult showOMenu(sf::RenderWindow &window); MenuResult highlightButton(MenuResult menuresult); struct MenuItem { public: Text text; sf::FloatRect buttonrect; static void highlightRectOutline(sf::RenderWindow &window, Text text, sf::Color color); MenuResult action; }; private: MenuResult getMenuResponse(sf::RenderWindow &window); MenuResult handleClick(int x, int y); MenuResult handleButtonHover(sf::RenderWindow &window, int x, int y); std::list<MenuItem> menuItems; }; [/cpp]
[cpp] static enum MenuResult { Exit, Options, Back, ChangeResolution, Play, Nothing }; [/cpp] Enums shouldn't have a "static" prefix.
Sorry, you need to Log In to post a reply to this thread.