C++ :: Structures / Loops - How Not To Repeat Typing Same Code

Jul 27, 2013

I have a structure for 4 divisions, and can't figure out how to loop through it.

So I ended up writing everything for times.

If I had 500 divisions I wouldn't be able to get away with it!

How can I have the structure in array form so I can fill it via looping?

/*Headers*/
#include <iostream>//needed 4 input/output
#include <iomanip>//needed to round
#include <string>//needed 4 strings
using namespace std;//global namespace to avoid name clash
struct division {

[code].....

View 7 Replies


ADVERTISEMENT

C# :: How To Repeat Execution Of Code Using Counter

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

C :: How To Print Out Structures Using Loops

Jun 23, 2013

How to print out these structures using loops.. printing out these outputs using loops..

View 5 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/C++ :: Drawing A Rectangle Using ASCII Code And For Loops?

Apr 24, 2015

For a Texas holdem' project I need to be able to draw out rectangles using ASCII codes and for loops. I started the code

#include <iostream>
#include <string>
#include <Windows.h>

[Code].....

View 6 Replies View Related

C :: Method Or Process For Reducing Redundant Code In Nested Loops

Nov 8, 2014

Have an assignment due in a few weeks and I'm 99% happy with it My question is is there a method or process for reducing redundant code in nested loops. Ie my code compiles and runs as expected for a period of time and after a few goes it omits a part or prints an unexpected out ext so basically how to find when the redundancy occurs with out posting my code so I can learn for my self?

View 3 Replies View Related

C++ :: Dereferencing Void Pointers Through The Way Of Typing It

Jan 11, 2014

I want to know how to dereference a void pointer through the way of typing it.

Lets just say that I malloc'd a huge bunch of memory and i can do whatever i want

void* randomData = malloc ( 1000000 );

And i decide to make my own virtual 'int'

I am not sure how to do this.

*( int* ) ( randomData + 10 ) = ( int ) 323453 //323453 can be an int variable aswell

Im not sure if this is the right way to do perform a dereference.

This is an overview of what has to be done:
-The pointer has to be dereferenced
-Cast the pointer as an int pointer so we can change it like a normal 4-byte int
-Perform pointer arithmetic, so that the int can be placed anywhere we want

View 8 Replies View Related

C++ :: Constructing A List To Typing Numbers And Count Them

Dec 17, 2013

i have read a lot of about lists but i dont understand this. I know its something like dogs on leash where we have

dog1->dog2->dog3->....
and
Code:
struct DOG
{char* (name of a dog of first leash)
DOG* (next dog ) } I have written something like this but this doesnt work as i wanted Code: #include <iostream>
using namespace std;
struct line {

[Code]....

I wanted to make program where i can type XX numbers , then cout those numbers without changing the order, and my next exercise is to change order in this programme from end to start.

View 7 Replies View Related

C :: Number 1 Appears In Next Line Every Time On Typing A Character

May 17, 2014

Everytime I type a character, the number 1 appears in the next line. And i just keep getting the message "Wrong! I have more than that." even when I type a number bigger than 1023

Code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void) {
srand(time(NULL));

[Code] ....

View 10 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++ :: Repeat Character Array

Nov 1, 2013

I'm having a little trouble writing program that on remove all repeat characters and leave only the non repeated characters. This is want I have so far.

#include <iostream>
#include <cstring>
#include <string>
unsigned repeatingCharCount(char const* s) {
std::string unique ;
const unsigned length = std::strlen(s) ;

[Code]...

View 6 Replies View Related

C++ :: How To Get Array To Repeat Itself After It Hits 9

Sep 13, 2013

How can I get the array to repeat itself after it hits 9?

So like this 0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8 and so on?

#include <iostream>
using namespace std;
int main() {
const int arraySize = 20;
int arr1[arraySize] = {0,1,2,3,4,5,6,7,8,9};

[Code] ....

View 3 Replies View Related

C++ :: Create A Loop That Repeat Itself Many Times A Second?

Aug 6, 2013

I create a loop that would repeat itself many times a second? Trying to do extremely basic graphics with a grid and system("cls") every time I run a command, but it still looks very jumpy. I realize system calls are evil. Any way to get rid of this too.

View 1 Replies View Related

C++ :: Repeat Found - Deleting In A Vector

Oct 12, 2013

I created a very basic program which contains a vector (my vector) that holds 0, 1 and 1. This program compares each element in the vector. If the element after the one currently being compared is equal to it, it outputs "repeat found!" Now this all works perfectly, but my next step was to erase the repeated one. Everything was working up until the delete step. I get a weird error that says "vector iterator not dereferencable" .

// vector::begin/end
#include <iostream>
#include <vector>
using namespace std;
int main () {
vector<int> myvector;

[Code] ....

View 6 Replies View Related

C++ :: How To Repeat For Next Word Not Exiting The Program

Sep 16, 2013

everything works it just how am i repeat for the next word not exiting the program.

// Word Jumble
// The classic word jumble game where the player can ask for a hint

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
enum fields {WORD, HINT, NUM_FIELDS};

[Code]...

View 1 Replies View Related

Visual C++ :: How To Make Random Array To Not Repeat

Feb 17, 2013

Here is my code for a simple game. paste it and try it.

#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;
int main (void) {
stringg[4],

[code]...

What they do (enter 4 actions)?

";
for (int ai = 0; ai < 4; ai++)
getline(cin, a[ai]);
cout << "

Where is happening (enter 4 locations)?

";
for (int li = 0; li < 4; li++)
getline(cin, l[li]);
for (int c = 0; c < 4; c++)
cout << g[rand() % 4] << " and " << b[rand() % 4] << " are " << a[rand() % 4] << " from a " << l[rand() % 4] << endl;
return (0);
}

At the end in the 4 lines some of the names, actions and locations repeat. How do I make them to not repeat and use every name that you will enter? do I need random_shuffle? How can I integrate it in my code?

View 1 Replies View Related

C++ :: Array Matrix - Extract Values Which Does Not Repeat

Jul 27, 2013

I have an array matrix called tmat,,and i know that in every row of tmax there are values which repeat two times...and am writing a code to extract the values WHICH DOES NOT REPEAT into another matrix called tcopy...the codes compiles fine...and it writes nicely to file...but without the desired result...

One last question...how can i get the array tcopy written to file in the form 5x3...and not all the figures in line one after the other? i mean i wish to see the matrix like a matrix on file..not like a list of numbers....

Code:
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const int R = 5;
const int C = 5;

[Code] ....

View 14 Replies View Related

C :: Program That Will Repeat K Times Each Single Occurrence Of A Vowel?

Jun 8, 2014

Repeat the vowel Problem 3 (0 / 0)Write a program that will repeat k times each single occurrence of a vowel in the input file "sp.txt" to a new file "output.txt". The first line of the input file contains only the parameter k. The first line (containing the parameter k) should not to be written in the output file.

I wrote the code but i cant figure out something. i read the file, i found the vowels but then i cant print them.

Code:
#include <stdio.h>#include <string.h>
#include <ctype.h>
#define MAX 100
int checkvowel(char c)

[Code].....

View 6 Replies View Related

C :: How To Repeat A Loop Based On Number Inputted By User

Oct 21, 2014

How can i repeat a loop based on the number inputted by the user?

View 4 Replies View Related

C++ :: Repeat A Question Over And Over And Calculate Total When User Wants To Quit

Feb 27, 2014

Write a program which is used to calculate GPA based on the grades from different courses Input by the user. User should be able to enter as many course unless they choose to quit. Once the user has completed entering the data, the program should be able to provide a feedback on the GPA. Where A=4, B=3, C=2, D=1.

View 1 Replies View Related

C :: Print Out - Array Code And Pseudo Code?

Apr 15, 2013

I have assignment which requires me to print out and array code and a pseudo code. I dont no what a pseudo code is,.

View 2 Replies View Related

C++ :: Reducing Code Duplication From Common Code Calling Common Class

Apr 13, 2014

I have a class 'A' which is almost perfect for my needs. Class 'B' uses class 'A' I've now designed Class 'C' and Class 'D' and noticed that there is a good chunk of code in class 'B', 'C' and 'D' for using Class 'A' is duplicated. I've separated out this code in specific, standalone functions in each of the classes. Now I'm wondering where this code should go. At the moment, the functions are duplicated in the three calling classes (B, C and D). Placing the functions into class 'A' would break the single responsibility principle. Inheritance to add functionality would likely break both SRP and LSP. The one that seems that it may work is composition.

However, Is designing a complete class just for a few functions over kill?

Would it be valid for classes 'B', 'C' and 'D' to access both the new class 'E' (which would depend on A) and the old class 'A' (which would have to be the same instance as the instance in the new class 'E'), or should the new class 'E' provide sufficient functionality so that Classes B, C and D don't need to access Class A directly? It would seem that its then an incomplete interface of the original object with additional functionality (ie, incompatible) Or should I do it a completely different way?

View 4 Replies View Related

C++ :: For And Do While Loops

May 10, 2014

I this notation:
for (; *strings[i]; i++)

the same as:
do {
i++
} while(*strings[i]);

?

View 2 Replies View Related

C :: Finding Next Day Using Structures

Jul 21, 2013

Ok, for my Sunday homework I have to find the next day of the year using structures. Now, I can get the structure to read the entered date (tested that with a simple scanf to printf entered data), but I need to get it to be able to tell that it is the end of the month and print out the next month when necessary. Here is what I got so far:

Code:
//Cameron Taylor
#include <stdio.h>
struct Date{
int month;
int day;
int year;

[Code] ....

As you can see, I am trying to use an array for the max day of each month (excluding Leap Year for now).

Where I use the entered month to = 'i'. Then I use 'i' as the position in the array to see if next.day is = to the max day of that position of the array.

I am having no compiler issues with GCC using -w or -Wall, but after entering the current day the program stops working and doesn't go beyond the input.

commiedic@localhost Project18$ gcc -o -Wall Exercise4.c
commiedic@localhost Project18$ gcc -o -w Exercise4.c
commiedic@localhost Project18$ gcc -w Exercise4.c
commiedic@localhost Project18$ make Exercise4
make: `Exercise4' is up to date.

[Code] .....

View 13 Replies View Related

C :: Not Using Structures For Project

Apr 5, 2013

I have to do a project for Programming and he said in quotes

"Programming exercise 10.6: the programming project is as described, except do not represent the points using structures.

Assume, as known, the ten (x,y)-values corresponding to x=0.0, 0.1, 0.3, 0.45 ..etc and use y-values from the

function xsin(x); as in (x,y)=(x, xsin(x)) = (0.3, 0.3sin(0.3)).

Use value n+1=10, so the LaGrange polynomial will be order = 9."

What does it mean to not represent the points using structures??

View 2 Replies View Related

C :: Integer Sum Using For And While Loops

Mar 6, 2015

I have an assignment that calls for a C program using a for loop AND a while loop that will receive an integer (called daNumba) and double it -- Using the integer the program will call the sumFor function and then the sumWhile function. These functions will both sum the values from daNumba to (daNumba * 2) ifdaNumba is positive. If daNumba is not positive it will add the values from (daNumba*2) to daNumba. Both functions will receive the value of daNumba and return a summed value. The only difference between the 2 functions is that sumFor will only use for loops and sumWhile will only use while loops. We are not to use arrays.

The program compiles without error. So far my while loop works for positive integers, but not with a negative integer (I have it commented out) I cannot get the for loop to work properly This is what I have so far -- I am stuck....

Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main () {

[Code] ....

View 12 Replies View Related







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