C++ :: Flow Chart For Nested Loop

Jan 6, 2014

how to draw a flow chart for following nested loop?

for(int r=1;r<=5;r++){
for(int c=1;c<=r;++c){
cout<<c;
}
cout<<endl;

View 1 Replies


ADVERTISEMENT

C++ :: Place Nested Loop Where Nested Not Necessary?

Apr 3, 2014

I wrote this code, and everything was working well, but part of the assignment is that it must include nested loops. Once I added the nested while loop, which is basically an if statement, my life was ruined. I am trying to nest a loop in the code that will basically tell the compiler that if the value "loopVol" were to exceed the value of "final" after adding an increment, to run the program for the "final". How can I do that?

Example:

initial = 10
final = 123
increment = 10

as of now, the program would stop at 120, but I want to nest a loop that will tell the compiler to calculate at the final if this happens.

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

[Code]......

View 3 Replies View Related

C++ :: Variable Nested For Loop

Mar 25, 2013

This code is used in scientific calculation for optimization problem.

Basically a particle is moving in a three dimensional space, its position is (x,y,z).

At each position, there is a fitness value associated with that position.

The fitness value is given by fitness(x,y,z) (code line 12~19).

We need to find out, when the particle moves around randomly, what is the highest possible fitness value.

To solve this, below code is used, and it produces correct result.

#define DIMENSION 3
#define MAXX 4
#define MINX 0
#define MESHsize 1
#include <iostream>
using namespace std;
float maxValue = 0.0;

[Code] ....

The output of the code:

[ fitness(0,0,0) = 0] [ fitness(0,0,1) = 1] [ fitness(0,0,2) = 4] [ fitness(0,0,3) = 9]
[ fitness(0,1,0) = 1] [ fitness(0,1,1) = 2] [ fitness(0,1,2) = 5] [ fitness(0,1,3) = 10]
[ fitness(0,2,0) = 4] [ fitness(0,2,1) = 5] [ fitness(0,2,2) = 8] [ fitness(0,2,3) = 13]
[ fitness(0,3,0) = 9] [ fitness(0,3,1) = 10] [ fitness(0,3,2) = 13] [ fitness(0,3,3) = 18]

..... so on

Answer: highest fitness = 27

Note: In this case, the values of x,y and z is integers from 0 to 3 inclusive.

For 3-dimensional space above, actually the code had run through 3 nested "for" loops.

Question: Above code works for 3-dimensional space. How to generalize the code, so that it works also for N-dimensional space, where N is an arbitrary integer?

( Note: possibly N = 30 )

View 19 Replies View Related

C/C++ :: Nested For Loop Pattern?

Nov 3, 2014

I'm trying to output a pattern using loops. The pattern is a plus symbol made of 3 rows of 5 x's followed by 3 rows of 15 x's and finally 3 rows of 5 x's.

I can get the program to output all 9 rows with 5 x's but I don't know how to do the 3 rows of 15 in the middle. I have tried a while loop and also an if statement but nothing seems to work.

#include "stdafx.h"
#include <iostream>
#include <iomanip>

[Code]....

View 8 Replies View Related

C :: Breaking Out Of While Loop With Nested If Statements

Mar 14, 2014

Code:

while(x==1){
for (i=0;i<j;i++)
{if (word1[i] == word2[i])
{prefix[i]= word2[i];
counter++;}
else
x=2;}

Basically after the 3rd run of the for loop, it encounters a contradiction. I want it to exit right there and then. Instead it continues to run the for loop. What can I do?

View 4 Replies View Related

C++ :: Continue Statement In Nested Loop

Feb 9, 2014

I was wondering how I could use a continue statement that continues in a nested loop. For example if I have

for (int i=0;i<amount;i++) {
for (int j=0;j<I[i];j++) {
for (int k=j+1;k<I[i];k++) {
if (P[i][j]+P[i][k]==C[i]) {
//What should be here?
}
}
}
}

If the condition is met then the most outer loop (in i) should continue to the next iteration.

If i simply fill in continue; in before the comment then it only continues the loop in k so that is not what I want.

View 5 Replies View Related

C++ :: Triangle In Nested While Loop Using Counters

Mar 13, 2013

How to make triangles using c++, in nested while loops.

The triangles were:
*
**
***
****
*****
******
*******
********
*********
**********

I have made a code for this:

int counter=1;
while (counter<=10){
int counter2=1;
while (counter2<counter){

[Code] .....

I was not quite sure about this one.

View 5 Replies View Related

C++ :: Decipher Program - Nested Loop

Feb 17, 2013

I'm writing a series of basic decipher programs and I have run into an issue where I get the correct answer when I start the loops at the iteration that contains the correct answer.

Code:
// generate key "words" with length of 3
for (int x = 0; x < 26; x++){
for (int y = 0; y < 26; y++){
for (int z = 0; z < 26; z++){

[Code] ....

This is the essence of the loop, I've attached the program in its entirety if necessary. Basically what happens is if I start the loops at x = 17, y = 7, z = 12, then I get the correct decipher shifts but if I start at 0,0,0 whenever it gets to that iteration (12,000 ish) the shifts are off by 2 or 3. "koq" should translate to "the" but im getting "dcz". Is this a simple bug in the or is something moving to fast for something else to keep up?

l3_ws.txt
main.cpp

View 1 Replies View Related

C++ :: Read A File With 2 Numbers In It - Nested For Loop

Mar 17, 2013

I am attempting to read a file with 2 numbers in it. The first indicates the number of rows the second, the number of columns. So for a file (Data.txt) that contains the numbers 5 7, I want to display

0 0 0 0 0 0 0
1 1 1 1 1 1 1
0 0 0 0 0 0 0
1 1 1 1 1 1 1
0 0 0 0 0 0 0

and write that output to a file.I can display the correct number of rows and columns but I can't figure out how to display alternating rows of 0's and 1's.

#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream inFile;//declare file

[code]....

View 5 Replies View Related

C++ :: Count Function - Nested Loop Output

Feb 28, 2013

What does the following nested loop output ?

count = 1;
while (count <= 11) {
innerCount = 1
while innerCount <= (12 - count) / 2) {
cout << " ";
innerCount++;
} innerCount = 1;
while (innerCount <= count) {
cout << "@";
innerCount++;
} cout << endl;
count++;
}

View 9 Replies View Related

C/C++ :: Writing Multiple Files In Nested Loop?

Jun 3, 2014

I would like to do something like this:

for (int i=0; i<5; i ++)
{
for (int j=0; j<5; j++)
{
//* CREATE A NEW FILE FOR WRITING * //
}
}

I don't know how to create a new file that doesn't get overwritten each time the loop runs.

View 13 Replies View Related

C/C++ :: Writing Into A Text File Using Nested For Loop?

Nov 15, 2012

My program involves trajectory planning using cubic spline method for a robotic arm. In the process, I had to calculate joint angles for each point in the path. In the last few lines of the code I need to write the values for counter and theta1 into a text file which I called "Test.txt". I am doing this using a nested for loop(the counter runs until it reaches 19 and hence need 19 theta1 values corresponding to it). However, I can't get all the theta1 values transferred to the text file.The statement within my inner loop is wrong and don't know how to fix it.
 
for(i=0;i<num_via;i++){
            current_time = GetTickCount();  
            //joint[0] = mult_joint[i][0];
            //joint[1] = mult_joint[i][1];
            //joint[2] = mult_joint[i][2];
            //joint[3] = mult_joint[i][3];      
            
[code]....

View 3 Replies View Related

C/C++ :: Finding Average Time Complexity Of A Nested Loop?

Oct 29, 2014

We were discussing how to find average time complexity of different algorithms. Suppose I've a the following nested loop

for(int i=0;i<n;i++)
{
min = i;

[Code].....

Now the outer loop will iterate N times. the inner loop will always iterate 3 times no matter what the value of N is. so the worst case time complexity should be O(n^2) but what about the average case and the best case? I mean in terms of searching we can figure out and distinguish between the worst,best and average as it depends upon the number of comparisons. But here how can the average and best case be different then the worst case.

View 13 Replies View Related

Visual C++ :: Unable To Iterate Over A Vector In Nested For-Loop

Jan 20, 2014

So I have this problem with not being able to iterate over a vector in a nested for-loop. Here's the nested for-loop:

bool innerHit = false;
for (std::vector<Sprite*>::iterator outerIter = sprites.begin(); outerIter != sprites.end() && (!sprites.empty()); outerIter++) {
Sprite* spriteOne = *outerIter;
for (std::vector<Sprite*>::reverse_iterator innerIter = sprites.rbegin(); innerIter != sprites.rend() && (!sprites.empty()); innerIter++) {
Sprite* spriteTwo = *innerIter;

[Code] .....

What happens is, after having called the collisionDestroy-function and the program tries to execute the nest loop in the outer for-loop, it all crashes with the text "Expression: vector iterator not decrementable", which I understand is because the iterator will have already become useless. The question is: know this, how do I fix it? I can't seem to get a hang of it.

Here's the collisionDestroy-function (the collisionReaction does nothing but sets a few local variables):

void Enemy::collisionDestroy(std::vector<Sprite*>& sprites) {
for (std::vector<Sprite*>::iterator iter = sprites.begin(); iter != sprites.end(); iter++) {
Enemy* tmp = dynamic_cast<Enemy*>(*iter);
if (this == tmp && collisionType == 3 || collisionType == 1) {
sprites.erase(iter);
break;
}
}
}

View 14 Replies View Related

C++ :: Using DirectShow To Control Flow Of A Program

Jul 18, 2014

I am having trouble understanding what I need to do to halt the flow of a program until a video file finishes playing. So far I have accomplished getting the video to play, but the program continues while the video is playing rendering the content of the program on top of the video making it not seen.

My goal is to make the video play, then once it has finished the rest of the program should run.

So far I have this in the start up area of my code:

//Initialize components for DirectShow to stream a video at start-up
CoInitialize(NULL);
//creates filter graph manager

[Code].....

After this code runs once, the program proceeds immediately into the loop where my update and render functions for the program runs. Preferably, I want to stop just the render function while allowing the update to continue to check if the user presses a key to skip the video. What do I need to add to the code to do this?

View 1 Replies View Related

C++ :: Code Flow (loops And Arrays)

Feb 13, 2013

I am having problems understanding where this code is wrong as I believe that I am not receiving the correct outputs. I have truncated the code to the most pertinent.

The algorithm asks that every value in array1 be divided by array2

and if that value is less than the ratio * array3 (percentage filter) then output.

I have no problem with the code with the exception of abs(ratio*array3[m]

Assuming that the ratio = 1 then all values get outputted, I want the array1 (first value) to have the first value in array3 assigned to it, the second value in array1 to have the second value in array3 to be assigned.

So:

array1 (1.0) with array3 (0.05)
array1 (2.0) with array3 (0.06)
etc.
or
array1 (1.0) with array3 (0.05)
array1 (3.0) with array3 (0.07)

Code:
array1[5] = {1.0, 2.0, 3.0, 4.0, 5.0};
array2[5] = {1.0, 2.0, 3.0, 4.0, 5.0};
array3[5] = {0.05, 0.06, 0.07, 0.08, 0.09};
ratio = abc/def;
for(int m=0; m<5; m++) {

[code]...

View 2 Replies View Related

C++ :: Writing Pseudo Code And Flow Charts

Apr 15, 2013

I have finished writing the code for the following program. I have concerns with the pseudo-code that I have written and the flow chart seems really complicated. I dont know how to build it. Here is the question:

An Internet service provider has three different subscription packages for its customers:
Package A: For $9.95 per month 10 hours of access are provided. Additional hours are $2.00 per hour.
Package B: For $14.95 per month 20 hours of access are provided. Additional hours are $1.00 per hour.
Package C: For $19.95 per month unlimited access is provided.

Write a program that calculates a customer s monthly bill. It should ask which package the customer has purchased and how many hours were used. It should then display the total amount due.

Input Validation: Be sure the user only selects package A, B, or C. Also, the number of hours used in a month cannot exceed 744

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

[code]....

What should be my pseudocode and flowchart ? Can i copy and paste my pseudocode here ?

View 2 Replies View Related

C/C++ :: Flow Meter - Count Certain Quantity Of Fluid Then Light Up Corresponding LED

May 6, 2014

I am attempting to write some code for a flow meter and LEDs using my Arduino. I need the flow meter to count a certain quantity of fluid, then light up an LED which corresponds to that quantity. I found this code on the internet and it was exactly what I needed but when I opened up the serial monitor to see if it worked it didn't. I have finally fixed the issue with it not counting anything at all, but it is still acting as if it was measuring the rate. how it counts and keeps track of how much fluid in total has passed through the flow meter ?

volatile int NbTopsFan; //variable to accumulate the number of pulses
float Calc = 0; //the volume flowed since measurement started, liters
void pulse() //This is the function that the interupt calls
int hallsensor = 2; //The pin location of the sensor

const int led1Pin = 3; //pin for LED corresponding to volume1
const int led2Pin = 4; //pin for LED corresponding to volume2

[Code] .....

View 13 Replies View Related

C++ :: Draw 2D Bar Chart According To 10 Or 15 Numbers?

Nov 26, 2013

I want to draw a 2D bar chart according to 10 or 15 numbers in c++. How can i do it? Which i need components?

View 1 Replies View Related

C++ :: Array Sales Bar Chart?

Dec 17, 2012

I need to make a bar chart with asterisks that looks like this:

Store 1: ******
Store 2: ***
etc.

anyway, right now what I have is:

Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
const int STORES = 5;
int sales[STORES], i;
for (i = 0; i < STORES; i++) {

[code].....

It's not displaying asterisks.

View 1 Replies View Related

C :: Make A Live Price Chart Graph

Dec 14, 2013

The only language I know so far is C. Is there any way I can use c programming to display a live chart for a price graph including volume in different time intervals that I want to select. I want it to look like this URL....

View 2 Replies View Related

C# :: Chart In Winform Displaying Wrong Point

Nov 11, 2014

I have the following code. I have hardcoded the x and y values to test. And for some reason for the point (0,-0.5) it plots (1,-0.5) . What is going on, because if you try other values then the graph displays correctly.

foreach (var grp in q) {
point = new DataPoint();
Sum1 = grp.Sum1 > 2 ? 2 : grp.Sum1;
Sum1 = Sum1 < -2 ? -2 : Sum1;

[Code] ....

Attached is what is displayed.

Attached image(s)

View 13 Replies View Related

C# :: Create Line Chart That Will Be Universal For Every Currency

Dec 30, 2014

I need to create a line chart that will be universal for every currency. As Y it will display value of currency, as X it will display time when that value was established.

For drawing I think of using Windows.UI.Xaml.Shapes.Line and Windows.UI.Xaml.Controls.Canvas

What I want to get is something like image below but it would have to draw correctly scaled chart for every currency which is the biggest problem(I think it is).

For every currency I will probably have to get minimal and maximal value which will be used to properly scale a chart(I will probably also have to get rendersize of canvas or something).

The user will choose the range of time and then the correct chart must be drawn (For example 04-11-2004 to 11-03-2007)

It is a windows store project.

View 4 Replies View Related

C Sharp :: How To Move Points Of Chart In C# By Mouse

Nov 27, 2014

I am Trying all the Time to implement in c# moving of points by using Mouse ( Web Applications) and save the new value in array. But not successful ...

View 3 Replies View Related

C/C++ :: Round Robin Execution With Gantt Chart - Arrival Time And Burst Time

Mar 10, 2015

This is a round robin execution. with gantt chart. arrival time and burst time. I think there is an error in my formula to get the right answer,i cant resolve it but my program is running. What is the code or the right formula??

#include<stdio.h>
int main(){
int i,j=0,n,time,remain,flag=0,ts;
int sum_wait=0,sum_turnaround=0,at[10],bt[10],rt[10];
int ganttP[50],ganttStartTime[50];
printf("Enter no of Processes : ");
scanf("%d",&n);
remain=n;

[Code] ....

View 2 Replies View Related

C :: Nested For Loops

Jun 1, 2013

What output would you expect from this program?" The output was not what I expected. I've psuedo-coded this out and I'm still missing something.

Code:

#include <stdio.h>
int main () {
int numbers[10] = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int i, j;
}

[code]....

The output: Code: 1 1 2 4 8 16 32 64 128 256 So when I look at this first loop I see that j = 0, which is less than 10, so then the program statement should commence, which is another for loop. So in this inner for loop I see that i = 0, which is not less than j, so this loop should terminate. Then the value of j increments by 1 and the first go around of the loop has completed.

Now I see that j = 1, so this is less than 10, and the inner for loop commences once again. This time though, i actually is less than j, so numbers[1] = numbers[1] + numbers [0], or numbers[1] = 0 + 1. Now the value of i is incremented by 1 and the first go around of this inner loop has completed. Then the value of j increments by 1 and another go around of that loop has completed.

So now j = 2, i = 1, and numbers[2] ( which is 0 ) = numbers[2] + numbers[1], or numbers[2] = 0 + 1. I was expecting the output to be an array full of 1's. However this is not the case..

View 6 Replies View Related







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