C++ :: Why Cannot Jump Out Of For Loop

Jun 6, 2013

I got code like this:

#include <iostream>
#include <vector>
using namespace std;
const long nx(3);
const long ny(3);
const long seal(-1);
long TotP(0);
class pore {

[Code]...

I can print out all those TotP, but cannot get Finish loop print out, why? If I put any statement below, which seems won't be executed, it is like it never jump out from the loop and die inside.

View 9 Replies


ADVERTISEMENT

C :: Trying To Scanf A Char And Code Just Jump Over It

Jan 25, 2014

I'm doing a code to calculate the final grade of students. This is a work for college, and I need to keep this structure.

My problem is that last scanf, it is ignored when I compile the code. It "works" if I try to scan a string, float or int.

Code:

#include <stdio.h>
#include <stdlib.h>
void nfinal(float NOTA1,float NOTA2,float NOTA3,char MEDIA){
int NOTA;
if(MEDIA=='A'){
NOTA=(NOTA1+NOTA2+NOTA3)/3;

[Code]....

View 3 Replies View Related

C# :: How To Jump From One TextBox To Next When Press Enter Key

Apr 13, 2014

How can i jump from textBox to next texBox when i press enterKey in c# , what i the event for that .....

View 2 Replies View Related

C/C++ :: Jump Table Instead Of Switch Cases?

Aug 14, 2012

I have an issue with switch case. There are about 32 cases to be handled in switch. each case just assigns a hexadecimal to a local variable.

#define ADFV 0x0301
Switch(error_index)
{
case 1:
var = ADFV;
........
}
}

can i use jump table for above issue to reduce the code size.

View 4 Replies View Related

C/C++ :: Conditional Jump Or Move Depends On Uninitialized Value(s)

Nov 24, 2014

I am getting this message from Valgrind, As far as I can see what it points to is initialized. The memory it is referring to is freed in unload and I was not getting this error until after I added the check function. Valgrind was happy. Here is the code and the error message from Valgrind. I am trying to create a spell checker for an assignment for a online class I am taking. I just want to get this table working correctly before I add it to the rest of the program. The code seems to run fine but I have come to see that dos not mean much in C.

#include "hashTable.h"
#include <stdbool.h>
table_node hash_table[TABLE_LENGTH];
bool loaded = true;
//assigning letters a-z to table nodes for buckets
void key_hash_t( )

[Code] ....

Valgrind error:

arortell@gentoo ~/Development/Projects/C_Projects/Data_Structures/HashTable $ valgrind --leak-check=full --track-origins=yes ./hashTable
==11360== Memcheck, a memory error detector
==11360== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==11360== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info
==11360== Command: ./hashTable

[Code] ....

View 10 Replies View Related

C++ :: Conditional Jump Depends On Uninitialized Value Valgrind

Jan 10, 2013

I have airport class which should navigate planes, in its list to runways, with method move, theres a method prepare which changes the direction of flight to all planes, always before move is called, move just increments decrement x and y of plane in its list. But after calling two times in row airport->move(), I get screwed and I really dont know wheres the problem. Have I badly initiazed something? Iterator gets invalidated.

Valgrind Stacktrace
Conditional jump or move depends on uninitialised value(s)
==26207== at 0x409601: plane::move() (in /home/xnovak11/Downloads/airport/main)
==26207== by 0x401FBD: airport::move() (in /home/xnovak11/Downloads/airport/main)
==26207== by 0x405FE1: io::start(std::istream&, std:stream&, std:stream&) (in /home/xnovak11/Downloads/airport/main)

This is how I add planes into list in airport

Code:
list<plane*> planes;
list<plane*>::const_iterator planeIterator;
list<plane*>::iterator planeIteratorMoj;
bool airport::addPlane(const plane& p) {

[Code] .....

This is the method where it fails. When I call it once, no problem, after second call I get instead of normal number in cout<<after move<< s1 i get like 8795456 ....

Code:
void airport::move() {
for(planeIteratorMoj = planes.begin(); planeIteratorMoj!= planes.end(); planeIteratorMoj++) {
plane * p1 = (*planeIteratorMoj);
int s,w;
p1->getPosition(s,w);

[Code] .....

View 3 Replies View Related

C :: Loop Does Not Work And Program Quits Without Displaying For Loop Function

Oct 13, 2014

We are making a program--but every time we input a value for scanf, the following for loop does not work and the program quits without displaying the for loop's function. We are not getting any errors.

View 11 Replies View Related

C# :: Use Loop To Load Two Forms Back And Forth Then Stop At Loop 4

Feb 15, 2015

I have tried to submit this topic before but i didn't submit my whole code and it was removed. So here it is. All I am trying to do is load form2 from form1 then back to form1 from form2 for a certain number of times the get out of the loop. I am new to C-Sharp and it seems as though I cant seem to figure out a way to do this.

Here is form1 and form2 code. I have commented out a few things I have tried.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;

[Code]....

View 3 Replies View Related

C :: Extra Loop Being Executed In Do-while Loop

Jul 1, 2013

Code:
#include <stdio.h>
#include<ctype.h>
void try5t(){

char choice;
int choiceint;

[Code] .....

Loop is repeated an additional time as shown in the screenshot:

View 9 Replies View Related

C++ :: How Much Milliseconds To Loop Through For Loop

Feb 20, 2014

Given a for loop:

int i;
for(i = 0; i < 1000; i++)
;

How many nanoseconds, or microseconds or milliseconds does it take for each iteration? And why do some use it as a timer mechanism?

View 3 Replies View Related

C/C++ :: How To Change For Loop Into Do While Loop

Apr 19, 2014

I already made a nested for loop into a while loop (below this) and now I'm trying to make the outer for loop into a do while loop, but it's not working.

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

[Code]....

And I can't make this code do the same thing. It stops after one loop, instead of continuing to the end. Why won't the loops continue?

#include <iostream>
using namespace std;
int main(){
int len;
cout << "Enter a number: ";

[Code] ....

View 2 Replies View Related

C/C++ :: Convert A While Loop To A For Loop?

Mar 25, 2012

I need to convert the following while loop:

count = 1;
while (caloriesForItem != 0, count != numberOfItems )
{
cout<<"Enter the calories: ";
cin >> caloriesForItem;
totalCalories += caloriesForItem;
count++;
}

This is what I have come up with:

totalCalories += caloriesForItem;
for (count = 1; caloriesForItem != 0; count != numberOfItems)
{
cout<<"Enter the calories: ";
cin >> caloriesForItem;
count++;
cout << "Total calories eaten today = " << totalCalories << endl;
}

However the output is not the same?

View 6 Replies View Related

C# :: Loop Within A Loop?

Sep 25, 2014

I for the life of me can't get my logic straight. I have 2 lists, 1 a list of text, and the other a list of int.

Here's my main list: List<string> ListNeedToADD = ListOfSPSExt.Except(ListOfReportExt).ToList();
Here's my second list:IEnumerable<int> result2 = Enumerable.Range(1, Convert.ToInt32(myValue)).Except(hostList);

I need to loop through my main list, ListNeedToADD, and for each item in that list, grab 1 value from the 2nd list and send those 2 items to a method. Something like this:

foreach (string myString in ListNeedToADD)
{
foreach (var item in result2)
{
intSort = item;
insertReportLimits(attribTable, myString, intSort, con);
}
}

The problem with doing it the way I am above is it loops through ALL the items for each myString.

For my method, it needs to look like this: insertReportLimits(attribTable, "34257", 22, con); then it would move on to the next: insertReportLimits(attribTable, "34854", 27, con); etc etc.

View 4 Replies View Related

C/C++ :: Cannot Get Out Of Loop

Feb 22, 2015

I can't get out of my loop to fill the array. This array should stop and print after 10 inputs. but it keeps asking for input.

This is what my code is supposed to do. Use 0 as sentinel for an array. Only positive ints will be entered into the array. A negative int should result in an error message, then input will continue. The numbers will be inserted into the array in ascending order. Do not insert them then sort the array.

#include <iostream>
#include <cmath>
using namespace std;
const int arraySize =10;

[Code].....

View 4 Replies View Related

C++ :: For Loop To Count Down From 10 To 0

Apr 16, 2013

I am using a for loop to count down from 10 to 0 it's working to count down from 10 to 1 but when the program cames to the 0 then the program freezes by any reason.

Code:
#include <iostream>
using namespace std;
int main()
{
int number[2];
cout << "Enter number: ";
cin >> number[0];
if (number[0] == 1)

[Code] ....

View 11 Replies View Related

C :: Function To End A Loop?

Nov 8, 2013

Is there a way to end a loop ?

Code:
while ( menuopt == 1)
{
printf("Lets start
");
printf("12 x 4 = ?
");

[Code] ....

View 2 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 :: Two Repeat One While Loop

Apr 17, 2014

So I have a programming assignment.

Code:
#include <stdio.h>
int main(void)
{
int input;
int sum;
int i;
int t;

[Code] .....

So you input an integer ex) 30

the printing of t =(i+i)+1 and i++ is carried out until i=30, which is when the sum of all the t's is printed.

If the value you entered is not an integer, the loop ends.

I'm supposed to do this with one while loop, and no more. I can't use the for loop either.

How can I do this?

View 7 Replies View Related

C :: Possible To Output By Using Only One Loop

Jul 21, 2013

is it possible to output like this using only one loop? if yes, how?

target output Code: ABCDE

EDCBA here is my code but using one loop im not getting my target output Code: #include <stdio.h>

main()
{
int x, y;

for(x='a', y='e'; x<='e'; x++, y--)
{
printf("%c
%c", x, y);
}
getch();
}

View 6 Replies View Related

C :: While Loop Not Disengaging

Nov 16, 2013

I have a while loop that will not disengage when the input given as "exit".

Code:
while (orders != "exit"){
for (i=0;i<25;i++){
for (j = 0; j<50;j++){
if (i == x && y == j){
printf("H");}
else {
printf("%c", map[i][j]);}

[Code]....

View 1 Replies View Related

C :: Can't Stop While Loop

Dec 6, 2013

I'm trying to create a connect four game, but I've ran into a problem while trying to read valid user input.

Code:

// 4 in a row game
#include <stdio.h>
#include <stdlib.h>
#define NUM_ROWS 6
#define NUM_COLS 7
}

[code]...

If the user enters an invalid number, then it works fine, but if a character is entered, the while loop in main never breaks.

View 9 Replies View Related

C :: Variable In While Loop

Feb 6, 2013

I'm writing a program to sum up the even numbers in between 1 and 100, using a while loop. At the beginning of my program, I initialize a variable "sum" to 0, and a variable "temp" to 1. Afterwards I enter a loop where I determine if "temp" is even or not, and if so add it to sum. However, at the end of my program, when I print "sum", I get a result of 0. Below is my code.

Code:

#include <stdio.h>
int main(void)
{
int sum = 0, temp = 1;
}

[code]...

View 4 Replies View Related

C :: If Loop Not Activating

Nov 24, 2013

Why my if statement for argc <3 will not execute? as the one for argc >3 does...

Code:

#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]){
int i;
int fnlength = strlen(argv[2]);
char *namein = argv[2];
int j = (fnlength-1);
char input[100000];
}

[code]....

View 2 Replies View Related

C :: Do While Loop Error

Feb 19, 2015

While trying to redo everything in c i have an error on a do while loop and i don't understand i've corrected everything else but i don't understand why the error occurs even though it says how to fix it it says error expected ) before token -line 18 part of code

Code:

int main(){
Beep (523,1000); // sound at 523 hertz for 1 000 milliseconds
char cPresent;
do
}

[code]....

this is just extra bits i've added on to the assignment but I've worked on the c++ code for a week now i have less than a day to redo it

View 2 Replies View Related

C++ :: While Loop Keeps Asking For Input After EOF

May 11, 2013

This is an example from C++ Primer on while loops shortened for simplicity:

int main() {
int value = 0;
while(cin >> value) cout << value;
return 0;
}

When I compile and run the above code the program keeps asking for input after I input nothing but pressing ENTER no matter how many times. The only way I can get it to stop asking for input is to input something other than an int such as a char or string. Program executes as intended after that. I have googled this issue and read all seemingly relevant results and nothing seems to pertain to my exact problem. I think it may have something to do with my computer's own settings or something and am baffled as to what it may be.

View 10 Replies View Related

C++ :: Using While Loop For Factorial

Mar 2, 2014

I need to write a complete program using "While Loop" to calculate 1! to 12! using just "int" variables. Only from 1 to 12 and there are no other inputs.. This is my first time using While loop.

View 2 Replies View Related







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