C :: For Loop - Stop Condition

May 23, 2014

I found a for loop in an example that I don't understund fully.

Code:
for (i=64; i; i/=2)
printf("i: %d
",i);

Now this is dividing by 2 until it reach '1' and stops. But why does this stops?

View 6 Replies


ADVERTISEMENT

C++ :: Using Pow (x Y) As Loop Condition

Oct 6, 2014

I've written a bit of code :

#include <iostream>
#include <cmath>
#include <cstdio>
int main() {
for(int i=1; i<=1000; i++)
for(int j=i+1; j<=1000; j++)
for(int k=j+1; k<=1000; k++)

[Code] ...

Now why does defining the if condition as if(pow(i,2) + pow(j,2) == pow(k,2)) doesnt work (ie. doesn't print anything) while defining it as if(i*i + j*j == k*k) works flawlessly - by working I mean printing out single set of 3 numbers.

View 4 Replies View Related

C++ :: While Loop Condition Not Working Correctly

Dec 8, 2014

The while loop part of my program isn't working right. stringOriginal is an array. If a large amount of characters passed the max 80 im processing is typed, it goes into a infinite loop. Also the condition doesn't work i type in quit and the loop continues.

while(stringOriginal != "quit"){
std::cout << "Enter a string of characters you would like to reverse
";
cin.getline(stringOriginal,79,'
');
}

View 1 Replies View Related

C++ :: Make A Loop Inside A Condition?

Oct 26, 2013

I need to do make a loop inside a condition. Can it be done? I don't want to call another function to do it. Any way at all without calling separate function inside the if? I just want to do:

if (
for (int i = 0; i<=10; i++)
{
//stuff related to the for loop
} )
{
//stuff related to the initial if condition
};

View 7 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/C++ :: Comparing Pointer To Variable As While Loop Condition

Aug 11, 2014

I'm writing a delete function for a linked list, and I'm having issues with this bit of code:

void deleteNode(int data){
node* del = NULL;
t = h;
n = h;
while(n != NULL && n->_data != data){
t = n;
n = n->next;
}
}

Or more precisely, this portion:

&& n->_data != data

n is my new node variable, _data is the storage variable in the private section of my class, and data is the information being searched for that needs to be deleted. Everything works without this section of the code. My assumption is that n->_data is somehow wrong, but I don't see how. I've tried everything I can think of- using parenthesis, using the variable rather than the pointer, I've tried expressing the pointer in a different way, I've tried using my t variable rather than n, and I've found examples online that use this exact same expression without any issues.

View 2 Replies View Related

C :: Calculating Loan Balance - Finding The Condition For Loop

May 18, 2013

Write a program to calculate the Loan Balance, where a person borrows an amount A and in return he/she agrees to make N payments per year, each of amount P. While the person is repaying the loan, interest will accumulate at an annual percentage rate of R, and this interest will be compounded N times a year (along with each payment). Therefore, the person must continue paying these installments of amount P until the original amount and any accumulated interest is repaid.

NOTE: The formula to calculate the amount that the person needs to repay after T years is-

Balance Amount after T years = A[(1+R/N)^NT]-P
-----------------------------------------------------------

I have a few doubts :

1. I think that the "balance amount" formula can directly give the "loan balance" for the person. I'm not sure if it's correct but in that case the question would serve no purpose. Maybe I'm wrong.

2. If there should be a loop to calculate the loan balance, what condition should I give and which loop will be better to use?

View 11 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/C++ :: While Loop To Stop After Third Entry

Jul 6, 2014

Having multiple issue trying to get a while loop to stop after the third entry.

#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
using namespace std;
int mySequentialSearch() {
int value;
string line;

[Code] .....

I am just working on the while loop right now. Then the function after I get the loop working.

View 10 Replies View Related

C++ :: Stop Infinite Loop By Pressing Enter

Apr 12, 2014

I wondering how to stop a infinite loop. The program clears a file then opens it and refreshes it over and over(the file is going to be modified by another program). I want it to start from the beginning anytime i press enter or escape, it doesn't really matter as long as you can restart it.

Here is the complete code:

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <conio.h>
#include <windows.h>
using namespace std;
void x() {Sleep(1000);}

[Code] .....

View 2 Replies View Related

C :: If Statement Won't Check The Second Condition?

Sep 24, 2013

I've tried retyping the code several times and didn't work for some reason the If wont accept both Q and q it just accepts Q.

Code:
#include <stdio.h>
int main(void)
{
printf("A menu will show up and you choose the number for the selection you want.

[Code].....

View 9 Replies View Related

C :: Scanf With Stopping Condition

Mar 22, 2013

I wanted to input some numbers with scanf function, i can enter some numbers and if I input -1 to the scanf, the input must end. And the scanf function has limited input, the max that I can input is 40 numbers.example if enter 1 2 4 6 5 4 -1 the scanf function will ended and the result will be appear.I wanted to know how the scanf function is like that would be best for this problem, Code: scanf("%d", &n); the result if I input those number will be like

|
||
||||
||||||
|||||
||||

View 3 Replies View Related

C++ :: Generalizing Condition In If Statement

Jul 29, 2014

I want to write an if statement which has condition like

if(i%1==0 && i%2==0 && i%3==0 && i%4==0 && i%5==0 &&
i%6==0 && i%7==0 && i%8==0 && i%9==0 && i%10==0 &&
i%11==0 && i%12==0 && i%13==0 && i%14==0 && i%15==0
&& i%16==0 && i%17==0 && i%18==0 && i%19==0 && i%20==0)

This of course is not the right way to write it. How to generalize it so that I can check the condition not only till 20 but till any number without manually adding all conditions.

View 2 Replies View Related

C++ :: If Else Statement With Ctime Condition

Oct 17, 2014

I am try to make a menu for deliver order program.

The menu divide into 3 group which are breakfast, lunch and dinner. However breaker only available at 6.30am-10pm, lunch available at 11am-1.30pm and dinner only available at 6.00pm-8.30pm

Let say my current time on the system is 10.30am, and the user select breakfast order. It should not available at this time, and prompt a message to use that the order not available at this period.

How to write the program?

View 4 Replies View Related

C Sharp :: Condition For Add New Row In Datagridview

Sep 13, 2014

I have two table the first is called Imprrests and the second is called ]IprestsPays. There is an Imprest_ID column that is primary key in [icode]Imprests[/code] table and foreign key in ImprestsPays table

Imprests table consists the following columns:
Imprest_ID,  Impres_value,  Imprest_date,    Employee_ID

Where Employee_ID column is primary key in Employees table and foreign key in Imprests table.

ImprestsPays table consists the following columns:
ID,  Payment_value,  Payment_date,  Imprest_ID

My problem is in the buttonadd_click event in Imprsts form.

I want to prevent user from insert any new imprest for employee in Imprests table if employee haven't paid all payments in ImprestsPays table for old imprest...

View 1 Replies View Related

C++ :: If Function Is Executed Without Its Condition Is True

Mar 5, 2013

I am trying to write a simple program that produces different outputs based on entered age of two different users. Program should tell who is older and behave different if both users are older than 100.

Here is my program: Code: #include <iostream>
using namespace std;
int main()
{

[Code].....

Why program executes this when both users are obviously more than 100

View 8 Replies View Related

C/C++ :: Char Condition In If Statement Not Working

Feb 3, 2015

I'm trying to get an if/else statement to work using a character condition, but it is a no-go. After I input either a 'y' or 'n', the program just sits there until I press 'Enter' again, at which point it ends. It never actually goes through either of the 'if' statements. At first I only had a single '=' in the condition, but I found that that was wrong. When I corrected it to '==' it still didn't work. I also tried clearing the buffer by adding a 'getchar()' at the beginning of the program, but that didn't work either.

#include <stdio.h>
#define std_rate .8855
int main(void) {
char ans;
int counter = 1, euros = 5;
double dollars = 0, ex_rate;

[Code] .....

The compiler (Visual Studio 2013) requires me to use 'scanf_s' instead of just 'scanf' for some reason, and if I don't have two 'getchar()' commands at the end, then it won't stay open long enough for me to see the results.

View 2 Replies View Related

C++ :: Multi Condition Function For Char Type

Jan 30, 2013

I have always written like a>='0'&&a<='9'&&a>='a'&&a<='z' in loops etc, but no more. Basically add whatever you want to condition, and if you want point a to point b just separate them with a '-' sign. Simply

while(!isCharInside(x,"|a-zA-Z0-9.*/=|-|")){/*code*/}
bool isCharInside(char check,string condition="a-zA-Z*/+=|-|0-9"){
for(unsigned int x=0,z=getLenght(condition);x<z;++x){
if(condition[x+1]=='-'&&(condition[x]!='|'&&condition[x+2]!='|')){
if(condition[x]>condition[x+2])swap(condition[x],condition[x+2]);
for(;condition[x]<=condition[x+2];++condition[x]){if(condition[x]==check)return true;};x+=2;}
else if(check==condition[x])return true;
}
return false;}

View 1 Replies View Related

C++ :: Wrong Check For Batch Code Entry End Condition?

Jan 13, 2015

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

int check_Pythag(int DIMA, int DIMB, int DIMC) {

[Code] .....

View 4 Replies View Related

C++ :: Parsing A Text File - Detect When Certain Compilation Condition Begins

Dec 8, 2014

I'm parsing a text file, and I'd like to detect when a certain Compilation Condition - i.e. #ifdef - begins. The challenge is, that the condition can take any of the following patterns:

#ifdef (FLAG)
#if defined (FLAG)
#if (defined (FLAG))

(And perhaps I missed more)

I'd of course need to treat them all the same, as they are indeed the same. How would you know to treat them all the same?

View 2 Replies View Related

C++ :: Search And Find The Shortest Queue And Search After Some Condition?

Mar 7, 2013

I am trying to implement a Task scheduler where i have n number of tasks. The Idea behind my task scheduler is that in a loop of queues of a vector, task should get enqueued to the shortest queue among the loop of queues, which is done by the following code.

#include <vector>
#include <queue>
std::vector<std::queue<int> > q
int min_index = 0;
task t // implemented in the other part of the program

[Code] ....

Next i am trying to extend this paradigm to reduce the overhead time of the scheduler, Instead of searching the shortest queue every time, search after some condition ie. search the shortest queue after 5 tasks gets enqueued to the shortest queue.

i need to do something like this

#include <vector>
#include <queue>
std::vector<std::queue<int> > q
task t // implemented in the other part of the program
while(q[min_index].size()!=q[min_index].size()+5) // check whether current min_index queue's size is increased 5 more times if not goto enqueue

[code].....

View 1 Replies View Related

C :: Start Stop Watch

Feb 25, 2013

I'm new to C programming and am quiet lost, create a program that takes a start and stop time and prints the passed, or show me where I can find the information needed?

View 6 Replies View Related

C++ :: How To Stop Input After Certain Characters

Oct 23, 2013

I'm trying to get the user to input their 5 digit zip code but my problem is how can I stop the program after the five characters have been inputted. Also how can I only get numbers to be inputted cause so far letters can be inputted as well.

View 2 Replies View Related

C++ :: How To Stop Console From Pausing

Mar 6, 2014

Just a quick newbie question: I'm doing a console application and whenever I open a .exe using system(), the console pauses and does not run the next instruction until I close this exe. For example when I do this:

...
system("mspaint.exe");
printf("Hello");

It opens ms paint and does not print the next message until Paint is closed. How do I work around this?

View 1 Replies View Related

C++ :: How To Stop Displaying The Console

Mar 6, 2013

I am trying to display a messagebox, but instead of just displaying the message box, there is also a console the pops up. How do I prevent the console from popping up? I'm using Visual Studio 2012. I'm creating an empty project, but I still get the console.

View 1 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







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