C/C++ :: Infinite Looping For Map?

Jan 13, 2015

I have been trying to get this piece of code to work but it seems to be running infinitely. What i'm trying to do is that whenever the iterator points to the map element, I check whether the element is 1 or 0. If it is 0, *do something*. But if it isn't, it should not do anything and proceed to the next element in the map.

//infinite loop - not working!
for (MapType::iterator p = pwCounter.begin(); p != pwCounter.end(); ++p) {
if (p->second.second != 1) {

[Code]....

View 1 Replies


ADVERTISEMENT

C++ :: Looping With Different Values?

Dec 9, 2013

I want to write a loop to check for prime numbers. So I'm going to check only numbers ending with 1,3,7,9.

So I need a loop that will increment with 2,4,2,2 and again 2,4,2,2...

What king of loop is best, a 'for loop' or a 'while' with switches in it or something else?

Basically I need to increment three times with 2 and then with 4, three times with 2 and then with 4...

View 9 Replies View Related

C++ :: Program Keeps Looping Infinitely

May 21, 2014

Why this program keeps looping infinitely when i run it and try to put some input...

#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
using namespace std;
struct Account {

[Code] ....

View 1 Replies View Related

C++ :: Looping Through Template Objects In Map

Dec 30, 2014

How to get this code working

template <typename T>
class Dummy {
// Implementation
};
template <typename T>
class SomeClass

[Code] ......

View 4 Replies View Related

C++ :: Looping And Calculate The Percentage?

Mar 7, 2013

#include <iostream>
#include <iomanip>
#include <math.h>

[Code].....

I AM HAVING TROUBLE CALCULATING THE PERCENTAGE. I HAVE TO CALCULATE THE AMOUNT OF MONEY FOR 6 YEARS.

View 1 Replies View Related

C++ :: Looping In CPP Class File

Jan 4, 2014

I have a class with a .h and a .cpp file. (I'm unique!) In the .cpp file, I have a loop and a nested loop. It worked fine when it wasn't in a separate file. Now, the loops will not loop and the value found at the end is some random out of the all park number because no looping took place. I am positive that the conditions and variables are set properly.

View 1 Replies View Related

C/C++ :: Cannot Find Out Why A Certain Part Is Looping

Jan 20, 2015

I am having a little bit of trouble with what should be a simple part in my code. For some reason it keeps looping the name part of the program and I seem to be passing over the problem in the code.

Here is the code:

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

[Code]....

View 6 Replies View Related

C# :: Looping Through A Range Of IP Addresses

Feb 6, 2014

I want to take a starting IP on a local network, and loop through to an ending IP on a local network, pinging all the IP addresses in between. For instance, ping all IP addresses between 192.168.1.1 - 192.168.1.255 (user enters desired starting IP and ending IP in text boxes).

I have the ping functionality working, and i can make it all work with lots of messy string parsing.. but it seems sloppy to me.

I have to split the strings (start and end IP) to get the last octet, then subtract to get the range of IPs. Then loop through, adding 1 to the last octet, and converting back to a string each time.

The C# Ping class can use either a string or an IPaddress for its Send method. If I use IPAddress, I just have to convert it from the text box it originates in, but the adding 1 to the last octet in the loop is a hassle.

Anyway, I guess the only question I have is, if you had to loop through a range of IP addresses, how would YOU do it?

public Job(string ipStartIn, string ipEndIn) {
long ip1 = Convert.ToInt64(ipStartIn);
long ip2 = Convert.ToInt64(ipEndIn);
IPStart = new IPAddress(ip1);
IPEnd = new IPAddress (ip2);
this.deviceAlive = false;

[Code] ....

View 14 Replies View Related

C/C++ :: Looping Recursive Functions?

Feb 10, 2014

how to recursively modify my program. The problem I'm hacing is the the program is not looping correctly and also not printing the correct number. I've calculated the payoff correctly, also I've only been able to print the first section of R3. I can't figure out how to loop it to get R2 to stay at 2 then go to 3 after all possiblities of R2 at 2. Enventually, R1 will change to 2 then 3; 3 being the highest number earned. To be mentioned that will be three recursive function loopR1, loopR2, and loopR3 for each column.

The result of the program should look like:

R1 R2 R3
1 1 1 payoff is 1
1 1 2 .......... 1
1 1 3 .......... 1
1 2 1 .......... 1
1 2 2 .......... 1
...
...
...
3 3 2 .............. 5
this is what I have so far:

#include <stdio.h>
#include <stdlib.h>
int payOff(int r1, int r2, int r3);
void loopR3(int R3, int upto);
void loopR2(int R2, int upto);

[Code].....

View 12 Replies View Related

C/C++ :: Won't Stop Looping If Statement

Jan 22, 2015

My program is designed to take a reading from a glucometer and light an LED if the reading is too high or too low. I used this code:

#include <eHealth.h>
void setup(){
pinMode(13, OUTPUT); //first alert
pinMode(12, OUTPUT); //green LED

[Code]....

The glucometer stores the tests and the code just pulls the most recent one, however even if I unplug the glucometer the first if statement keeps repeating and the LED in pin 12 keeps shining. Is it the if statement itself malfunctioning, or is the Arduino storing the data it pulled and just repeatedly plugging that into the if loop?

View 3 Replies View Related

C++ :: Create A Program Using Nested Looping?

Nov 5, 2013

You are to create a program using nested looping. Your program is to have a menu asking the user to select which pattern to create and how many rows to use (it should accept 1 to 10 rows and keep the aspect ratio of the pattern). The patterns are 1 - Box, 2 - V, 3 - Inverted V. Note, if I select pattern 1 with 10 rows, the box will have 10 asterisks in the first row.

Okay so i came up with the box but i have been getting stuck at getting the V or inverted V.

View 1 Replies View Related

C++ :: While Loop Keeps Looping Without Getting Input From User

Dec 5, 2013

struct stu_dat //outside main function
{
int rollno;
char name[45],
float average;

[Code] ....

No compilation problem.when executing prompt waits for inputting rollno, but, as soon as i enter a char string it keeps looping displaying the "want to enter more data?".i cant understand what is going on,as there is no compilation problem and runs good till i input the name.

View 3 Replies View Related

C/C++ :: Looping Entire Block Of Code

Feb 3, 2014

I just want my program to run continuously until someone enters 0 to exit it. I tried doing while(x=1) and looping my entire block of code. Also there is a switch one is a for one is a while loop both doing the same function. I have basic error checking and whatnot.

/*This is a program that gets a user to input a starting and ending value.
The code then prints the number ie 1 and 5 would be (1,2,3,4,5) and all the squares and cubes.
There is a case statement asking weather you want to run it as a for or as a while loop.
The choices are case sensitive.
*/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>//allows for power and cube function
int x;
int main(){

[Code] ....

View 4 Replies View Related

C++ :: Looping Through A Vector Of Object Pointers

Sep 4, 2014

Lets say for example I have the following vector:

vector<Component*> mComponents;

and a function print() inside of class Component that prints the objects name.

How do I loop/iterate through the vector to access the print function in each object.

View 1 Replies View Related

C++ :: Nested Looping To Create A Pattern

Jul 15, 2012

I am working on some coursework for university at the moment, and one of the questions asks me to 'write a function that will generate the following pattern using nested looping techniques.'

Pattern:

- . . . . . . .
. - . . . . . .
. . - . . . . .
. . . - . . . .
. . . . - . . .
. . . . . - . .
. . . . . . - .
. . . . . . . -

So far I have the following code, but when I compile it I get a host of different errors.

#include <iostream>
int main() {
int A[8][8],i,j;
for(i=0;i<8;i++) {
for(j=0;j<8;j++) {

[Code] ....

How to add code tags on this?

View 13 Replies View Related

C :: How To Get Rid Of Infinite Loop

Mar 1, 2013

What I need to do to get rid of the infinite loop?

Code:
do {
printf("Enter the number of tests:");
scanf("%d", &test);
if (test< 0 || test> 4)
printf("Wrong number. Please try again!
");
}
while (test< 0 || test>4);

View 9 Replies View Related

C :: Why Keep Getting Infinite Loops

May 30, 2014

See code below:

#include <stdlib.h>
#include <stdio.h>

int main ( int argc, char *argv[] ) {
int P[150] = {}, i, j;
for ( i = 2; i <= 150; i++ ) {

[Code] .....

Using gdb, I noticed that the variable j keep going back to initial value after the interior for loop condition returns false. Why doesn't this for loop terminate right away?

View 6 Replies View Related

C++ :: Range-based Looping Over Container Of References?

Mar 6, 2015

Is it possible to create a class that stores (non-const) references to some objects and enables users direct access by using range-based for loops on them?

Code: class container {
public:
void add(int& value);
void remove(int& value);
...
};
int main()
{
container c;
for (auto& value:c) {
// `value' should be accessible as type `int&' instead of being a pointer, `std::reference_wrapper<int>' or something like that
}
}

View 6 Replies View Related

C++ :: Keep Looping Until User Enters A Blank Line?

Aug 4, 2013

My goal is to create a loop that keeps taking user input over and over until the user doesn't enter anything into 'cin >>', leaves the line blank, and simply presses the ENTER key to move on, at which point the program is supposed to break out of the loop and continue on with the rest of program execution. Something like this:

Code:
do {
cout << "
Enter a name: ";
cin >> input1;
if (input1.empty())

[Code] ....

As you can see, I've already tried using the empty() function, but that didn't work, the program simply stays in the loop and doesn't break out, no matter how many times I press enter. It just keeps prompting me to enter a name. I've also tried using something like

Code: if (input1 == "")

but that doesnt work either. How do I break out of this loop?

View 2 Replies View Related

C++ :: Keep Looping Until User Enters A Blank Line?

Aug 4, 2013

So I've run into the following problem. My goal is to create a loop that keeps taking user input over and over until the user doesn't enter anything into 'cin >>', leaves the line blank, and simply presses the ENTER key to move on, at which point the program is supposed to break out of the loop and continue on with the rest of program execution. Something like this:

do {
cout << "
Enter a name: ";
cin >> input1;
if (input1.empty()) {

[Code] .....

As you can see, I've already tried using the empty() function, but that didn't work, the program simply stays in the loop and doesn't break out, no matter how many times I press enter. It just keeps prompting me to enter a name. I've also tried using something like

if (input1 == "")

but that doesn't work either. How do I break out of this loop?

View 1 Replies View Related

C++ :: Looping Nested If With Random Number Generator?

Feb 25, 2015

Looping a Nested If w/ random number generator

View 14 Replies View Related

C# :: Looping Through Text File And Recalculating Some Values

Jan 20, 2014

I have chosen C# as our language . Students have to enter a name of a recipe, followed by the number of people it will serve, followed by a list of ingredients for a recipe. This, then, needs to be exported to a text file. This bit I am fine with.

They then have to import the file back into C# and recalculate for a new number of people. This is the bit I am struggling with. The calculation is fine, I can do that. The issue is getting it to loop around each column of data to not only perform a calculation (I have just set it up to multiply by an entered value for now). I have set up a text file with the following data in it:

2 grams sugar
350 ml milk
4 tsp lemon
5 tsp vanilla
6 cloves garlic

I want it to come back with, (if multiplied by 2 for example) something like:

4 grams sugar
700 ml milk
8 tsp lemon
10 tsp vanilla
12 cloves garlic

At present, it comes back with

4 grams sugar
4 grams sugar
4 grams sugar
4 grams sugar
4 grams sugar

Code is below.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication1{

[Code] .....

View 3 Replies View Related

Visual C++ :: Looping Lines And Blocks Of Characters

Mar 17, 2013

I have a file that is like the following, with patterns of pipes in it:

Code:
||| || | |
| ||| | | |
|| || ||

I have to consider each row of pipe characters to be in blocks of 3 characters each (e.g. - positions 1-3, then 4-6, etc, etc...) but I have to capture all of the pipes, in sequence, like so:

positions 1-3 for lines 1-3, then positions 4-6 for lines 1-3, etc, etc...

How to get this done besides writing severely redundant control structures like loops, one after the other?

View 5 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 :: Reading Infinite String?

Sep 24, 2013

I have made a program that can take an infinite string:

Code:

#include<stdio.h>
int main(void) {
int i = 2, j = 0;;
char *string;
printf("Enter any string:

[Code] .....

But there is some problem in it, like its printing extra characters after string. reading infinite characters in a string

View 11 Replies View Related

C++ ::  Number Counting Up To Infinite

Mar 1, 2014

#include <windows.h>
int main() {
int i;
int y=6;
int x=9;
gotoxy(x,y);
//gotoxy(x,y) must be the coordinate that the number lies in.

[Code] ...

How to make this program that the output is a number that counts up to infinite (or we say just like a timer but there's no minute just all whole number counting up ) using for loop ? and when the number changes it also change in color !
and the color of a number is according to the color attribute of console output.

View 2 Replies View Related







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