C/C++ :: Library Reserve System - Counter Variable?
Sep 15, 2014
I am writing a program that minicks the library reserve system at my university and the problem is that when i run the code and reserve a room i am to keep track of the amount of times the room has been visited. To do this i set up a array roomcount and I count up by one every time i assign a room, The bug lies with when you reserve a room, then run option three, it will show that the previous visits is at 1, which is good. but then if i leave the room(option 2) and then run option 3 again to view the status of the rooms, the previous visits is set back to 0, which is not good. Ive been staring at this for hours and asked numerous people by we can't seem to figure out why the roomcount variable resets.
#include <stdio.h>
#include <math.h>
int main (void) {
int choice;
int roomchoice;
int i = 0;
[Code] .....
View 4 Replies
ADVERTISEMENT
Oct 14, 2014
I'm trying to write a small brute force application in C on Ubuntu 14.04.1 using Code::Blocks with gcc-4.8.2. It's nothing special and just for practice.The focus is on a parallel procedure that generates strings by use of OpenMP. Every time a string is generated, the counter variable should be incremented. At the end, regardless of whether the search string was matched or not, it outputs the correct number of all generated strings (counts).It works fine so far.Here is my source code example:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <omp.h>
/* Global variables */
const char Literals[] = "abcdefghijklmnopqrstuvwxyz";
const int NLiterals = sizeof( Literals ) - 1; // NLiterals = 26 Bytes.
const char SearchString[] = "test"; // I.e. until 'test' there are 355414 counts.
char MatchString[16];
}
[code]...
This should speed up the process of generating strings. But if I do so, always when the program has a match the number of counted strings is wrong. Here are some possible "wrong" outputs: Code: Match: 'test'! 40710 tries. <-- number of tries (counts) is wrong! or Code: Match: 'test'! 40375 tries. <-- number of tries (counts) is wrong! But if the program doesn't have a match (i.e. when I change SearchString to something like the following line), then the number of counts is correct: Code: const char SearchString[] = "test0"; The only thing I have to do before, is to change the follow line from:
Code:
printf( "
No match! %u tries.
", Count / 8 ); to Code: printf( "
No match! %u tries.
", Count );
But also it can happen that there is no output. Like an infinite or endless loop. How can I improve the source code in order that the correct number of counts is always displayed and what can be the reason for the endless loops time after time? Both issues appears only by the use of Code: #pragma omp for schedule( dynamic ).
View 5 Replies
View Related
Feb 20, 2014
After searching, it seems that I've finally arrived at the good old traditional "Random Number Game". I've been presented with solving this problem in the context of Visual C#.
I've solved the first part of the problem: Have the user enter a random number, display "Too high" or "Too Low" depending on the entry. If user guesses, let the user know. That part of the problem I was able to solve with only 3 IF statements. In it's current version, instead of using all IF statements, I saw where 3 test conditional weren't needed. (If it's not greater nor lesser it's equal or,.... "otherwise do this").
An enhancement to the problem ask that the user be notified of how many guesses it took to get the number correct. I reasoned that number of guesses could be translated to mean " number of iterations ".
I'm having trouble using the counter variable to track the iterations, then display the total iterations. I'm not seeing how to increment that value with each loop. I've basically reached two results no matter how I've used counter and written the while loop. The first one returns back to me "the guessed number". Example, if I guessed 10 times and the lucky number was 58, the display statement in the ELSE clause became: "Congrats. You guessed the number in 58 tries!".
The other result is what's returned by the code in it's current form. I think it'll be clearer for me to debug from this point then the previous. Here, I can see how I reach "Congrats. You guessed the number in 2 tries!". It's apparent that counter is being incremented by one regardless how many guesses the user makes. On the contrary, it's not so apparent to me how previously, the value returned by the counter variable at the end of the loop was actually the value for the random number generated and the user's entry (hence, the correct number) and NOT the total loop iterations.
Here's the code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
[Code] .....
View 4 Replies
View Related
Oct 23, 2014
The question is: Define the class Counter. An instance of this class is used to count things, but the counter should never be less than 0 (non negative number). The member variable should be private. I realize what I'm suppose to be using but can't implement the member functions needed..
int main(){
int value;
cin >> value;
Counter myCounter(value);
for (int i = 1; i <= MAXLOOP; i++) {
myCounter.increment();
[Code] ....
View 3 Replies
View Related
Feb 22, 2014
I have to ask system (linux) for a value and then assign it to the variable.
Example:
unsigned char date[] = system("date");
Of course this is wrong, but illustrated what is my goal.
How to achieve this effect ? I've heard about POSIX but how to include and use it.
View 10 Replies
View Related
Sep 30, 2014
Im building a banking system. in my create_account it asks for account address and phone number as well as other questions. When I go to my Show account info (balance inquiry) I notice its not getting the right address as well as phone number. its showing "garbage".
Code:
/********************************************************************
* Vincent Dotts 09/29/2014 ch11.cpp *
* This program serves as a customer banking system *
*****************************HISTORY*********************************
* WHO DATE Discription *
*********************************************************************
* VD 09/30/2013 Created program *
********************************************************************/
#include<iostream>
#include<fstream>
[Code] .....
View 3 Replies
View Related
Nov 26, 2014
I have a situation where map elements will be inserted all throughout a continuous loop. I know that there's no reserve function for maps like there are for vectors, but I know exactly the maximum amount of elements there will be in the map, I just don't know the value of each individual map.
Would it be possible if I just inserted the maximum amount of elements in the beginning of the program, and change the value of each/any individual element later on? For example:
std::map<int, std::string> map;
//There will be a maximum of 200 elements in this map
for (int i = 0; i < 200; i++) {
map[i];
}
//Change the value of individual elements as I wish
Is it more efficient than initializing on declaration if initializing will be done often?
View 2 Replies
View Related
Oct 12, 2013
In my code I have a template class.
In the contructor, I create a new array arrray.
A pointer to this array is saved as an attribute.
The purpose of this attribute is that I should be able to call the array from within another function be typing *p or *(p+1) etc.
The only thing I forgot is that the array doesn't exist anymore when the constructor is done, right?
This means the space is no longer reserved for this array and the space is used for other things.
Is there a way to keep the array space reserved (even when the array does not exist anymore at the end of the function)?
View 1 Replies
View Related
Mar 7, 2014
We can construct vector in following ways
vector<int>v1; //create an empty vector
vector<int>v2(arr,arr+4); ///to create vector from an array
vector<int<v3(v2); //throuh copy constructor
But I have come across some program in a forum,they have create vector like this
vector<int>v(10,5)
I am clueless ,is this allowed?,what syntax allows this?
if a vector is create like this
vector<int>v(3);
v.push_back(1);
v.push_back(2);
v.push_back(3)
v.resize(2);
Now I am curious to know what are the changes those will happen in vector v because of resizing it?
View 1 Replies
View Related
Jan 17, 2014
I've been reading about libraries; How to make them, how to use them, the different types of libraries, etc..
When using a shared library, does the program require that library to be installed on the computer after the program has been compiled into an .exe?
Ie.. if somebody downloaded a "Helloworld.exe" that I had compiled on my computer using a shared library (that wasn't part of a standard operating system), would they also need that shared library on their computer for the program to run without errors?
and for Static Libraries, when I compile a program using a static library, does it include in the final binary only the functions of the library that are actually used, or does the compiler add in the entire library?
View 8 Replies
View Related
Apr 27, 2013
How do I add a counter for the comparisons so that it increments every time the two array value are compared?
// Session5.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
const int NMAX =10;
[code].....
View 1 Replies
View Related
Jul 30, 2014
int counter won't reset to 0 when I click the start over button.
protected void startOverButton_Click(object sender, EventArgs e)
{
gameOverLabel.Visible = false;
[Code]....
View 3 Replies
View Related
Feb 17, 2015
I am not sure why this is happening but I am simply trying to make rounds with my code and have it stop when one of two things, or both, happen.
#include <iostream>
#include "Classes.h"
#include "RNG.h"
#include "select.h"
#include "Fitnesschk.h"
using namespace std;
/*Global Variables************************************/
const int column = 32;
[Code] ....
I've tried resetting and renaming all variables but I don't see any conflict. I tried declaring in different areas but no dice. The other issue I have is that fittest always returns 0 even if the function returns 1. So it infinitely loops. When I go through looking at the variables. the fittest variable never changes even if the function returns 1 and round seems to reset after reproduce is called.
Here is the supporting code.
For Fittracker:
int fittracker(person man[], int row, int column){
for (int y = 0; y < row; y++){
int fit = 0;
for (int z = 0; z < column; z++){
if (man[y].data[z] == 1){
[Code] ....
View 10 Replies
View Related
Apr 14, 2013
One that fills different char arrays the idea is to use a single char to represent a char such as 255 but if more than it then use a char array of two chars to represent the next char 00 because if only one is needed it would take less disk space than 0,255 as it would in an array.
My goal is to do this all the way up to an array that can hold 255,255,255,255 but only use the more complex array if needed Example: a char of 255 takes much less space than a char array of 4 chars so that instead of 0,0,0,255 it is written to disk as a single char whereas a char array of 200,0,0,1 would be written as a 4 byte char array. use single char to represent values from 0 to 255 use two char array to represent 0,1 to 255,255 three for 0,0,1 to 255,255,255 and four for 0,0,0,1 to 255,255,255,255
View 3 Replies
View Related
Jun 18, 2013
I am trying to make a program which reads a text file, separates the strings into words, then finally saving and counting each different word.
When I comment out the code where it is supposed to search for the same word in the table, the program doesn't work.Am I doing something wrong with strcmp or the loop? The 'break' just exits out of that 'for' loop right?
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define WORD_MAX 500
#define LIST_MAX 500
int main(){
int i, j, find;
[Code]...
View 6 Replies
View Related
Jan 2, 2014
The program should be print the numbers 0 through 10, along with their values doubled and tripled. The data file contains the necessary variable declarations and output statements.
Example the output:
Single Double Triple
1 2 3
2 4 6
3 6 9
4 8 12
here my code tell me if correct
#include <iostream>
#include <cstdlib>
using namespace std;
int main () {
int x, double, triple;
[Code] .....
View 1 Replies
View Related
Oct 4, 2014
I need to get up to speed in Embedded systems. I need to create a 3led binary counter, when an input is operated the it needs to count up using these leds from 0 to 7. I have written this so far and how to pulse a counter or interger to 7 and then reset back to 0.
int main (void) {
LED_Init_1();
LED_Init_2();
LED_Init_3();
[Code]......
View 2 Replies
View Related
Feb 23, 2014
I have to write a program that asks the user to input a positive integer, counts how many primes there are before this integer, then divide the number of primes by the integer. Here's what I have so far:
int n;
int counter = 0;
cout<<"Enter a positive integer n.";
cin>>n;
[Code]....
the value of the integer counter is supposed to increase whenever a prime number is identified but it's increasing n times
View 8 Replies
View Related
Jul 26, 2014
I am trying to make a parenthesis counter using stack in C. But my code is always returning that my expression is invalid.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#define SIZE 100
#define True 1
#define False 0
struct stack {
int top;
char items[SIZE];
[Code] ....
View 5 Replies
View Related
Jun 3, 2012
How can i form a counter of say 30 elements so that to meet following requirement,
I need to access 5 elements out of 30 elements and out of these 5 elements once the one value is printed (i.e now access for remaining 4 element will be left) other one should get added immediately to this 5 element set, from remaining total 25 elements. In this way 5 element count will be there always.
I am trying this as follows, by forming vector of 30 elements accessing its 5 elements as :
for (iter = vector1.begin(); it < vector1.end();it++) {
for(int count = 5; count >= 1 ; count--) {
cout << "Print value<" <<count<<"> : "<< *it <<endl;
it++;
}
}
This displays 5 elements at a time but counter "count" waits for to finish off its remaining 4 elements however i want to maintain this counter to 5 elements always.
View 1 Replies
View Related
Apr 6, 2015
I am trying to modify a PerformanceCounter I have created in C#. But it doesn't seem to be that it is being changed. This counter needs actualy to be a flag : 0 or 1.
I took the following code from the web. It created the collectors category along with the counters well. But the RawValue always shows 0!
I am working on Win7/64.
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace PerformanceCounterSample
[Code] ....
View 8 Replies
View Related
Oct 22, 2014
I have a method that changes a canvas color after set intervals, e.g. start timer, 5 seconds green, 3 seconds red, then stop. This functionality is provided in the interval method. The problem I'm trying to achieve is getting this sequence to repeat for a set number of iterations.
I tried to solve this by setting up a counter after the timer is stopped but the code keeps repeating indefinitely by starting and stopping over and over instead of the max of 6 iterations I had set. In debugging the problem, I watched the value of 'i' and when the 'if' statement is set to false. The 'if' statement gets set to false after 7 iteration as expected but the start(); keeps getting called.
void myTimer_Tick(object sender, EventArgs e) {
//Assign text box string value to a time span variable.
TimeSpan workTm = TimeSpan.ParseExact(wrkString, @"hh : mm : ss : fff", CultureInfo.InvariantCulture);
TimeSpan restTm = TimeSpan.ParseExact(rstString, @"hh : mm : ss : fff", CultureInfo.InvariantCulture);
// update the textblock on the display
// with hh, mm, ss, ms
ms = myStopwatch.ElapsedMilliseconds;
[Code] .....
View 1 Replies
View Related
Jul 28, 2014
I have a counter that onclick should increment 1 and it does that on click, but if I click the button again, it won't increment again. Instead it will be stuck at 1. How can I make it go up if the button is clicked more than once? Also this is a web application.
protected void submitAnswerButton_Click(object sender, EventArgs e) {
int counter = 0;
if (mathAnswerTextBox.Text == answer.ToString()) {
answerStatus.Text = "Correct!";
[Code] ....
View 12 Replies
View Related
Jan 27, 2014
I'm working on a program that reads data in line by line from an input file and the sorts it into two arrays, one string, one float. They are parallel arrays managed by a running data count of how many lines are read in, however, I'm getting an error with my data count. My test file only has 8 lines but when I cout my data count, it's like 35,485 or something like that. Here's the code I have so far (my program still has other components to write but I haven't gotten that far.)
Code:
#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
#include<sstream>
using namespace std;
//global constants
const int MAX = 1000;// maximum numbers of input for array size
[Code] .....
View 14 Replies
View Related
Dec 1, 2014
I'm trying to create a program that rolls a dice a few thousand times and print out how many times it lands on each face and then print out a graph using x's as a visual representation using classes.
output looks like this:
1 --- 2000 xxxxxxxxxxxxxxxxxxxxxxxxx
2 --- 1950xxxxxxxxxxxxxxxxxxxxxxxx
.
.
6 --- 2050 xxxxxxxxxxxxxxxxxxxxxxxxxxx
I need a method called int count(int face) inside my class that returns the number of times a particular face has appeared, I just don't know how to incorporate this. I think I should use a constructor and destructor but i'm new with those and knowing when to actually use them.
Here is what I have so far that shows how it should look when printed, just struggling to convert using a class.
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;
[Code]....
View 2 Replies
View Related
May 9, 2013
The best I could come up with is this.
while(true){
wisdomCnt++;
_stprintf_s(szBuffer, _T("%i"), wisdomCnt/10000);
TextOut(hdc,120,10,szBuffer, _tcslen(space));
}
but the program is constantly loading and clicking anywhere causes it to stop responding. Is there a better way to do this especially in Win32 API?
View 6 Replies
View Related