So I already gave this a go and will post my code below. The question is about the last loop before the program cout's. i thought the count would keep track of the repeated numbers so i could display them but it does not. I italicized the loop i am referring to. or at least i tried to xD
#include <iostream> #include <iomanip> using namespace std; int main() { int inputs[30]; int numofloops; int maxvalue = inputs[0];
With out sorting and if the array size is changed and filled with different elements, mayb some that are all duplicates(in that case display message that says "No nonrepeated digits".
This seemed like a simple task but im failing to grasp some concept. if the array is 2,0,38,2,3,1,3 the first non repeated is 0. nested loop is how i went. i feel like im going to far with the counters than need be. just need first non repeated. if n equals 2 an o equals 0. and it iterates comparing 0,38,2,3,1,3 to n which is 2. repCount will b 1. if repcount was 0 then n would be the first non repeated number. im trying to consolidate my if else statements so there are not so many. This program fails if the array gets bigger say 2,45,2,7,1,8,9,45,1,10 .....
for (n=0; n<sizeof(digits)/sizeof(int); n++) { if(repCount<2) { // nonRepCount=0; for (o=n+1; o<sizeof(digits)/sizeof(int); o++)
I have generated a 10x10 integer matrix, by way of a 2 dimensional array, the elements are randomly generated and lie on 1 <= z <= 5. I am in need of an efficient method of setting all adjacent "duplicates" (repeating elements) of length 3 or greater to the integer six (6). The source for the brute method follows for clarity.
I want to calculate how many times the common number is repeated . So I have used freq[num] in that function. But I am getting the output like this-
Code:
The common number is = 5 The 5 repeated = 1 times The common number is = 6 The 6 repeated = 1 times
The common number is = 4 The 4 repeated = 1 times
The common number is = 5 The 5 repeated = 1 times
[code]....
So the freq[num] is only returning 1 instead of counting the total number of repeating which is wrong!! I would like to have somthing like this in my output -
Code:
The common number is = 5 The common number is = 6 The common number is = 4 The common number is = 5 The common number is = 5 The common number is = 8 The common number is = 9 The common number is = 6 The common number is = 6
I'm currently on an exercise that specifies that I find any repeated words, "the the" for example, in a string, print the word that is repeated and how many times said word is repeated using a while loop that reads one word at a time and break statements when a repeated word is found. Having a bit of a falling out with iterators tonight and I'm not doing to well.
#include <cstdlib> #include <iostream> #define TRUE 1 #define FALSE 0 using namespace std; typedef int Bool;
[Code] ....
Gives repeated digits in an integer but only in one condition : Only if the repeated digit is the result of n%10 where n is the integer the user writes. If the repeated digit is not the result of n%10 , then the compiler gives a wrong result.
so the question is : how to make this code gives the repeated digit in an integer (regardless the fact that the repeated digit is the result of n%10 or not and especially with making the minimum of changes on the code)????????? ?????
In the C++ book Programming: Principles and Practice Using C++, there's an example code like this for detecting repeated words:
Code: #include "std_lib_facilities.h" int main() { int number_of_words = 0; string previous = " "; // previous word; initialized to "not a word" string current; // current word while (cin >> current) // read a stream of words
[Code].....
The header file in there is sort of like a set of training-wheels for students who are complete beginners to the language; the function keep_window_open() is defined in there and it does just that on Windows systems where the output window closes too fast (in the case of the function, it's just like cin.ignore(), except it waits for you enter a character, like 'j', before it exits); programs on my Windows laptop work fine on Code::Blocks, but when I create a .exe file for them and double-click that file, it does actually close too quickly for me to be able to see the output (if it's a program like the generic "Hello World!" program that just outputs text to the screen and then exits - so all I see is the output window just flash-by really fast in those cases).
Anyway, as for the problem I'm having with the code: there are no error and compile- or link-time, but it does behave strangely at runtime, where the part inside the curly-braces of the while-loop doesn't execute at all.
I am working on a problem for the CS50 online course through the Harvard web site. I am trying to re-size a bmp image. They gave us a small program that copies a bmp image and we are to modify it to re-size the image. Here is the page [URL]..... Any way I am trying to move the file position indicator backwards so I can read the same line from the input file. So I can resize the file vertically I have the image resized horizontally but it keeps over writing the same lines vertically.
/** * bmp.h * * Computer Science 50 * Problem Set 5
Read in n, then n lastnames, and check to see if the first in the list is ever repeated again.Here's what I have so far:
Code:
#include <stdio.h> #include <stdlib.h> int strcmp(char *w1, char *w2); int main() { int j, n; char string1[30], string2[30]; }
[code]....
I see the problem is that it lies within n amount of string that I am not going through every string to compare to the first one.How will do compare every string to the first one?
I found a card shuffling function on a long dead thread.
Code: for (int x = 52; x > 0 ; x--) { y = rand() % x; temp = deck[x]; deck[x] = deck[y]; deck[y] = temp; }
I do not understand how numbers are not repeated in the function. It seems like it would be possible to get 2 cards with the same number with the above function.
I also am getting incorrect numbers. It seems like I should only get numbers between 1 and 52 (which is what I want). However, I am getting the number 0, and some number between 1 and 52 will be missing, but I will have a total of 52 unique numbers.
I played around with using 51 instead of 52, x > 1, and changed to --x and none of those produced the desired results.
I have several functions doing similar things, inside their implementations, the parameters are the same, but they call different methods.
I want to create one function to make the structure easier, and reduce the duplication. I heard template might be one solution. But I am not sure how to use it in this case.
and it wil output each word and maybe then can search for similar words if there would be 2 strings then i would use strstr but i dont know how to do with one string.
I wanted to print the values of a array from a function by passing the array as well as the number of elements to be read. For a single dimensional array, this is how i have written it. It's pretty straight forward. I want to read 5 elements from the 5th element in the array.
Code: #include<stdio.h> void display(int array[],int size) { int i;
[Code]....
With this code I want to print the five elements from the element present in [0][4].
But shows an error that
Code: D:BennetCodeblocks CLearning CSingleDimentionalArray.c||In function 'main':| D:BennetCodeblocks CLearning CSingleDimentionalArray.c|18|warning: passing argument 1 of 'display' from incompatible pointer type [enabled by default]| D:BennetCodeblocks CLearning CSingleDimentionalArray.c|2|note: expected 'int (*)[10]' but argument is of type 'int *'| ||=== Build finished: 0 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|
I know when you pass a array as an argument it gets decomposed into a pointer, but with a multi-dimensional array this is not the case. how this works for mult- dimensional array's?
I'm working on a game with an entity-component system. I have a Manager class that is handling all of the components by feeding them into vectors set up for each type of component. Right now I have a lot of repeated code for each kind of component.
I've tried generalizing this with templates, but I've been confused by how I should organize the collection of vectors for each component. I had it setup so that they were all in an unordered_map, but how to get the templated functions to find the right map slot to use based simply on the template's parameters.
The full project is here for reference: [URL] ....
At the bottom I have a loop that cout FI,XC,XL,I while going through the loop but when it prints its uneven and setw cant fix it. How do I print values of FI,XC,XL & I to an array so they are aligned.
Given an array with integer values in the range [0, 100], print the values by popularity (number of time it appears in the array).
example: array: 60, 60, 70, 80, 80, 80, 80, 100;
output: 80 80 80 60 60 70 100.
complexity restriction: should be linear.cant use advance data structure like lists or hashmaps, only arrays. structs are not allowed.
my idea: to build counter array of buckets of size 101, and count each value.then i need to sort the counter array(its still linear), but how i can keep track that the value of 80 appeared 3 time?I mean i need to sort the values of the counter with the indexes as well.
I'm having trouble with my for loop near the end of the program was able to print everything else.
Sample Output:
*** end of 27610_Arrays04.cpp program ***
City City Points --------------- 1---5----10---15---20 Belvidere ********** Freeport ******** Byron ************ Stillman Valley *************** Rockford *********
*** end of 27610_Arrays04.cpp program ***
Input:
TODO #1: complete the coding of the points array An integer array of 5 numbers: 10, 8, 12, 15, 9
TODO #2: complete the coding of the cities string array An string of 5 city names intialized to: "Belvidere", "Freeport", "Byron", "Stillman Valley", "Rockford"
Compile-time arrays with initialization lists.
Processing & Output:
TODO #3: complete the coding of the call to the printStars() function
TODO #4: code the printStars() function
#include <iostream> #include <iomanip> #include <string> using namespace std; int main(void) { /* declarations ------------------------------------------------*/