C++ :: Values Getting Stuck In Memory?

Apr 4, 2013

I have a school project where I have to create a class with 2 attributes that default to 1. To verify that they are at 1, I have a cout before any user inputs or value manipulation. It works for the most part. What happens is that if I change the defaults to 17, the cout will retain the old values until I have an unsuccessful build (remove a semicolon from the end of the line). When I have a successful build (put that semicolon back), the cout displays the changed values. Change the values back to 1 and the same thing happens again until I have an unsuccessful build then a successful build. Are the old values getting stuck in memory somewhere?

// Rectangle.h
// Chapter 9_Problem 9.11_Page 412
#include <iostream>
using namespace std;
#ifndef RECTANGLE_H
#define RECTANGLE_H
class Rectangle // Rectangle class {
public:
Rectangle(double = 17, double = 17); // default constructor setting values to 1

[code]....

View 10 Replies


ADVERTISEMENT

C :: Keep Track Of Size Of Blocks Of Memory That A Pointer Points To - Malloc Is Stuck On 8

Jan 8, 2014

I'm trying to keep track of the size of blocks of memory that a pointer points to. No matter what I do, this code below always outputs the integer 8.

If I change 1000 to 5, I still get 8. If I change it to 0, I get 8... If I change it to -1, I get 8. If I change int *a to double *a, I get 8. If I take away the & symbol, I get 8. If I use *& instead, I get 8.

Why? I want it to output 1000. If I change that to 500, I want it to output 500.

int *a;
a = malloc(1000 * sizeof(int));

int j = sizeof(&a);
printf("%d", j);

I want to build my skills where I can allocate, inspect and change memory sizes.

View 4 Replies View Related

C++ :: Assign Values To A Dynamic Memory Structure?

Dec 27, 2014

I create some code that assign values to a dynamic memory structure. I'm not sure why one code works and the other crashes when it assigns a value.

Working Code

#include <iostream>
using namespace std;
struct WorldOjectCollisionMap
{

[Code].....

View 6 Replies View Related

C++ :: Initializing Pointers To Memory Addresses Or Values?

Aug 31, 2014

What is the difference between initializing pointers to a memory address using the address operator like int *pointer = &x; or initializing it to a value like int *pointer = x; .. in other words how does p and q point to the same memory address in:

const int ARRAY_LEN = 100;
int arr [ ARRAY_LEN ];
int *p = arr;
int *q = &arr[0];

View 4 Replies View Related

C# :: Store Data In Memory After Adding Values

Oct 23, 2014

I serialize a XML file, and i have this values here:

public class ServiceConfig {
public List<DatabaseDescriptor> Databases { get; set; }
} public class DatabaseDescriptor {
[XmlElement("Name")]

[Code] ....

I have a form1 which is a datagrid view and get's updated like this:

dataGridView1.DataSource = xmlData.Databases;

Now i have a button: get tables, and it opens up form 2, there it's supposed to appear all the tables of the selected Database, when i click on the row i get the database name so i get all the list of Tables from

DatabaseDescriptor
where
DatabaseDescriptor.Name == name
(I get this when i select the row)

But then on the 2nd form, i also have 2 textbox so i add a new table, i add the tablename and id. the new value should appear in the datagridview of the tables, and when i close it and reopen it, it should be there. Maybe i should concatenate first the values or something, how do i do?

View 3 Replies View Related

C++ :: Correct Values Passed To The Pointers - Memory Corruption

Apr 26, 2012

My project is say that it has memory leaks. When I view it in the debugger, it shows the correct values being passed to the pointers.

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
bool ConfigGetEntry( char *pcFile, char *pcNameMust, char* &pcResult ) {
char pcBuffer[ 512 ];

[Code] ....

Its saying that i have memory corrupting at..

Code:
if ( !ConfigGetEntry( pcFile, pcName, pcRet ) ) return _strdup( pcDefault );

Also is it normal to have a bad pointer then point data into it to then clear that of the bad pointer. To have valid data now in that pointer.

View 3 Replies View Related

C :: Why GDB Getting Stuck

Mar 2, 2015

so my program is quite simple and it works fine when i execute it but when i try to run through it with gdb i get an error. so this is what i get from gdb

Code:

Breakpoint 1, main () at fun.c:4
4 {
(gdb) watch a
Hardware watchpoint 2: a
(gdb) next
6 a=0;b=0;c=0;
(gdb) next

[code]....

View 6 Replies View Related

C++ :: Stuck With A Do While Loop

Mar 27, 2013

Alright I have a program that needs to calculate different rates of commission for a particular sale

I'm stuck in a loop and I'm not sure how to update the final cout statements as well.

#include <iostream>
#include <cmath>
using namespace std;

[Code].....

and yes those are the actual rates i need to calculate and they are in increments of 5%

View 2 Replies View Related

C/C++ :: Stuck In A Loop And Can't Get Out

Feb 15, 2015

how to ask for the input (className) without getting stuck in the loop. When I remove

char className;
cout << "Enter the class name: " << endl;
cin >> className;

it works fine. When I leave it how it's displayed below it goes in an infinite loop. By the way I think "char" is not the appropriate way to declare className. If I want to output it later, should I changed it to "string"?

#include <iostream>
using namespace std;
int main()
{

[Code].....

View 2 Replies View Related

C++ :: Dynamic Memory Is Affecting Non-dynamic Values

Oct 7, 2014

i'm implementing a playerclass for a game.. in the game there are multiple player types, weapons ect.. i just wanted to turn my players weapons into a dynamically allocated c_str. once i added my: Destructor, Copy Constructor and Overloaded Assignment Operator. My initial values became corrupted and i cannot fix them.

Player2.cpp
#include <string.h>
#include <iostream>
#include <cstdlib>
#include <iostream>
#include "player2.h"
#include "dice.h"
#include "gamespace.h"

[code]....

View 1 Replies View Related

C++ :: Stuck In Infinite Loop?

Feb 24, 2015

my code seems to enter an infinite loop should a user mistakenly enter a character other than a digit. The code is about selecting from a preset number of options, numbered 1- 4. If the user mistakenly enters a letter for example, instead of a number, the infinite loop kicks in...

View 1 Replies View Related

C++ :: Variable Stuck In A Loop?

Feb 7, 2015

I want to create a loop that that generates a random number set and gives the user the option to run the loop again for a new number. I have that working but when the loop ends the variable value does not leave the loop. I tried a posttest and pretest loop.

Is it possible to declare/create/alter a variable in a loop and have that value exit the loop to use in the code later? I am still learning about global variables.

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
int oneDiceSix() // Roll 1d6
{int oneDiceSix = 1+(rand()%6);
return oneDiceSix;} //end function

[code]....

View 2 Replies View Related

C/C++ :: Stuck On Using Pointers With Malloc

Apr 18, 2015

So this is my first attempt at actually writing code, I have a little basic core functionality set up and I'm 99% sure I'm doing something very fundamentally wrong with pointers.

#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
struct Creature {
int pow;
int tou;

[code] ....

Error generated:

magic.c: In function "main":
magic.c:71:26: warning: initialization from incompatible pointer type [enabled by default]
struct Creaturedb *db = Initialize_creaturedb;
^
magic.c:72:22: warning: initialization from incompatible pointer type [enabled by default]
struct Player *pl = Initialize_player;
^

View 3 Replies View Related

C :: Cannot Get Out Of Loop - Stuck With Updating Variables

Jul 18, 2013

Code:
#include<stdlib.h>#include<stdio.h>
#include<unistd.h>
#include<math.h>
int main(void)
{
double N, NG, LG, epsilon, root; // setting all variables to type double

[Code] .....

The goal is to create a program to calculate the square root of a number provided by the user to an error tolerance 0.005

Looking around i fond the Code: fabs(NG - LG) < epsilon); section that was very similar to what i was using, but if this is better im down for that.

My issue, from what i can see, is the updating of the values of LG. if the test for error tolerance fails then LG needs to take on the value of the results of NG.

Now I am not 100% that is the point of failure due to the fact the script does calculate the root properly, but it never exits the program once it reaches the tolerance level.

Code: imac:ENG-3211 user$ ./hw_4_1

Please enter the number you wish to find the square root: 4

4.00 2.500
4.00 2.050
4.00 2.001
4.00 2.000
4.00 2.000
4.00 2.000
4.00 2.000
4.00 2.000
4.00 2.000

And it continues forever until i manually break the program even though the answer was found, in this example, on the 4th loop.

View 8 Replies View Related

C Sharp :: Stuck In Infinite Loop?

Sep 9, 2012

I currently have a hangman game in the making. Which is giving me debugging issues when I go to pick a letter, it will keep asking for a letter, if I place a break; within the loop it asks for a letter and says you've won. I know all I should need is a couple extra lines somewhere within the code.

/// Play game
public static string playGame() {
Words words = new Words();

[Code].....

View 2 Replies View Related

C :: Got Stuck In Simple Coding Process / How To Initialize Any Value

Mar 2, 2013

in order to calculate some logarithm approximation I need to make a variable, say s, search through the whole integer numbers.

Code:
int s;
for {;;s++){
}

[Code] ....

since the variable needs to be initialized right? how to go through all the numbers?

View 3 Replies View Related

C++ :: Randomly Generating Probabilities - Function Stuck

Oct 29, 2014

I've written some code to randomly generate probabilities:

int Queue::car_per_hr() {
srand( time( NULL ));
int prob = rand() % + 101; // Probability in percentage from 0 to 100
int cars; //no of cars per hr

[Code] ....

So it checks through the range of possibilities: 0-20%, 21-40% etc. I then have this to implement it:

#include <iostream>
#include <ctime>
#include "queue.h"
using namespace std;
int main(){
Queue car_wash;
int NO_HOURS;

[Code] .....

For some reason though, everytime I call the car_per_hr() function, the probability just stays the same. It's output is always locked to the same thing it had to begin with?

View 3 Replies View Related

C++ :: Stuck On Getting Highest Number Output Using Array

Feb 25, 2014

Here is my code and everything works except i can not get the highest array number to be output. it always says 10.

My instructions are:

(1) Create a 10-integer array called data
(2) Set a pointer ptr to point to array data
(3) Output the elements in array data using pointer ptr
(4) Find the largest element in the array data using pointer ptr

#include <iostream>
#include <cstdlib>
using namespace std;

[Code].....

View 4 Replies View Related

C++ :: Stuck On Student Project / Classes And Objects

Aug 28, 2014

Working on a project for a c++ class and got a bit stuck.

What I am trying to do is include a class for calculating home square footage in a program I have written for my last project. When I do this, I get errors in codeblocks, on lines 74 and 87, "expected ; before 'box', and 'box' was not declared, respectively. Unsure what my snafu is... I had these two programs separate and both run without errors until I combine the two into one program.

View 2 Replies View Related

C :: When Try To Iterate Two Times Or More - Program Gets Stuck In Infinite Loop

Mar 18, 2014

I'm having trouble getting my loop to work correctly. If I iterate the for loop once it works as expected and displays proper output. When I try to iterate two times or more the program gets stuck in an infinite loop.

testData8.dat:

Code:
12 9
13 756

View 3 Replies View Related

C++ :: Math Game Program - Stuck On Input File

Oct 21, 2013

I am making a math game program that simple and need to have a user input a name and then that name.txt is brought up and use variables from the text to add to their score. heres my code kinda long.

#include <iostream>
#include <cmath>
#include <cctype>
#include <string>
#include <ctime>
#include <cstdlib>

[Code] ....

View 10 Replies View Related

Visual C++ :: Data Stuck When Debugging With Serial Port

May 10, 2014

I am making a MFC application with VC++2012 with receiving data from Serial Port and the data is stored in a Listbox, then after processing (convert into numbers) and get these data to draw a sine wave on the chart. (I intend to make a virtual oscilloscope).

Everything works ok at the beginning, but after receiving about 300 items or above (in the Listbox) the value seem stucking (or lagging) and work very slowly.

I receive data by the SerialPort_DataReceived() method, and process of converting and drawing chart also in this method, I think this makes the system overload!!

View 1 Replies View Related

C++ :: Program To Determine Slope Of A Line - Stuck On Commas When Entering Numbers

Jan 1, 2013

The program I have is from a tutorial where the user enters two points on a line, and then the program calculates the mid-point and slope.

I want to modify it from it's initial form so that co-ordinates can be input in (x,y) fashion. Right now the user has to enter the x-coordinate, enter a space, and then enter the y-coordinate (lame...)

I saw people using SStream and using that to either write functions to ignore the comma or similar things for converting one file into an array, but not quite what I am trying here.

// program to determine slope of a line

#include <ios>
#include <iostream>
#include <istream>
#include <limits>

using namespace std;
void myflush ( istream& in ) {

[Code] .....

View 2 Replies View Related

C++ :: Read In A Maze File To Move Smiley Face Around In - Stuck On A For Loop Entry

Mar 7, 2013

I am trying to get this code eventually to read in a maze file to move the smiley face around in. But right now my current snag is the yes or no to enter the for loop.

#include <iostream>
#include <windows.h>
#include <conio.h>
#include <time.h>
using namespace std;
int main() {
int name;
char ans;

[Code] .....

View 3 Replies View Related

C++ :: Random Number Generator Stuck On 1 Number?

Nov 21, 2013

I am working with C++ in Visual Studio. It's my first semester doing anything like this ever. Still, I am embarrassed that I am having trouble with this simple "coin flipping" program. The user tells the program how many times to "flip the coin" & then the program tells the user the results of each flip. You'll see I am randomly generating a 1 or a 2 within the function coinFlip to represent heads or tails. However, the problem is that if the user wants more than one coin flip, the "random" number stays the same for all of them, resulting in all heads or all tails. I am thinking this is an issue with the for loop that I have within the function coinFlip.

Code:

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;

[Code] .....

View 3 Replies View Related

C++ :: Read Unknown Number Of Integer Values And Then Print Count Sum And Average Of Odd Values

Apr 9, 2014

write a c++ program that reads an unknown number of integer values and then print count, sum and average of odd values, even values, positive values, negative values!!

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved