Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The way you are looping on the vector and returning true/false is weird and your app is crashing because of <code>checkVar()</code>.</p> <p>I encourage you to change all the loops on <code>varList</code> that search for an item to something more simple and easier to read, like:</p> <pre><code>bool checkVar(string varName) { // Check to see if varName exists for (unsigned int i=0; i&lt;varList.size(); i++) { if (varList[i].name == varName) { // If matches, return true; } } // If execution reaches here, it means it didn't found a match return false; } </code></pre> <p>This solves the crash. I don't know if your application has any other bugs, but this is my current output:</p> <pre><code>Building Generator 1.0 Alpha Variable Systems Test ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Enter a variable name: dog Enter a value (A FLOAT!): 2.2 Setting variable. Function returned 0 Enter a variable to check: alpha Variable "alpha" doesn't exist! dog 2.2 </code></pre> <p><strong>EDIT:</strong></p> <p>Another problem is with your defines: ERR_NONEXISTENT and ERR_VAR_EXISTS are both <code>1</code>. They should have different values! I'm pasting the relevant code below:</p> <p><strong>consts.h</strong>:</p> <pre><code>#ifndef CONSTS_H_ #define CONSTS_H_ #define VERSION "1.0 Alpha" // Variable errors #define ERR_NONEXISTENT 0 #define ERR_VAR_EXISTS 1 // File r/w errors #define ERR_FILE_OPEN 2 #endif /* CONSTS_H_ */ </code></pre> <p><strong>vsystem.cpp</strong>:</p> <pre><code>#include &lt;string&gt; #include &lt;vector&gt; #include &lt;sstream&gt; #include "vsystem.h" using namespace std; vector &lt;var&gt; varList; int addVar(string varName, float value){ // Check to see if varName already exists bool varExists = false; for (unsigned int i=0; i&lt;varList.size(); i++){ if (varList[i].name == varName){ varExists = true; return ERR_VAR_EXISTS; } } // Good! The variable doesn't exist yet. var tempVar; tempVar.name = varName; tempVar.value = value; varList.push_back(tempVar); return ERR_NONEXISTENT; } int changeVar(string varName, float newValue){ // Check to see if varName exists for(unsigned int i=0; i&lt;varList.size(); i++){ if(varList[i].name == varName) { // If it match, replace the value varList[i].value = newValue; return ERR_VAR_EXISTS; } } return ERR_NONEXISTENT; // Uh oh! } fetchResult fetchVar(string varName){ fetchResult returnValue; // Check to see if varName exists for(unsigned int i=0; i&lt;varList.size(); i++){ if(varList[i].name == varName){ // If it matches if (i == varList.size() - 1) { returnValue.good = true; returnValue.result = varList[i].value; return returnValue; } } } returnValue.good = false; // Uh oh! returnValue.result = -1; return returnValue; } bool checkVar(string varName) { // Check to see if varName exists for(unsigned int i=0; i&lt;varList.size(); i++){ if(varList[i].name == varName) { // If matches, return true return true; } } // If execution reaches here, it means it didn't found a match return false; } vector &lt; var &gt; getVarList(){ return varList; } string getVarList(string varDelim, string valueDelim){ stringstream final; for (unsigned int i=0; i&lt;varList.size()-1; i++){ final&lt;&lt;varList[i].name&lt;&lt;valueDelim&lt;&lt;varList[i].value&lt;&lt;varDelim; // add variable name, delim 1 (probably tab), variable value, delim 2 (probably newline) } final&lt;&lt;varList.back().name&lt;&lt;valueDelim&lt;&lt;varList.back().value; // same, but don't add a newline (or other) return final.str(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload