C++ :: Using Arrays To Find A Target Value?
Nov 25, 2013
I wanted to write a program that will determine a set of values that add up to a target value. I want to use 12 bins and fill the bins with random numbers between 0 and 20. Then, look for a target value of 30.
Here is what I have so far. (mix of actual code and Pseudocode.)
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <conio.h>
#include <stdlib.h>
int main (void) {
// columns: 0=value 1=checked 2=selected
[code]....
View 3 Replies
ADVERTISEMENT
Oct 6, 2014
Write a program that will generate, but not display, a three-digit "target" number that has three distinct digits. (Hint: use random number generator.) Then, input a maximum of ten user guesses and for each guess, output the number of hits and matches in the guess. Stop when the user guesses the number or runs out of guesses. For example, if the target is 427, the guess 207 has one hit (7) and one match (2).
View 8 Replies
View Related
Sep 24, 2014
This program does everything i want except for one major problem and one small one.
1. The program keeps taking my last entered number and counting it as max and min
2. When I go to end with 0 it adsd the enter number prompt then returns.
#include <iostream>
using namespace std;
int main()
{
[Code].....
View 1 Replies
View Related
Aug 12, 2014
I have an array of "2,3,4,5,6,9,10,11,12,99". I need to create a table of this which i have done using case
1. Find the maximum value of the array
2. Find the sum of the first and last element of the array
3. Swap the adjacent pairs of arrays
4. Display the values in array
5. Quit
Please enter choice:
but when i try running the program i did i keep having the break or continue pop up ....
#include <iostream>
using namespace std;
int main() {
int choice;
int number[10] = {2,3,4,5,6,9,10,11,12,99};
[Code] .....
View 6 Replies
View Related
Feb 6, 2014
I define "Comwords" as a string, but apparently it takes the members as chars, then I can't set strings in a structure equal to the chars.
I see to also be having unknown problems with the ComMAL array and loading it values into another element of the same structure.
How to correct this? I was thinking of casting char elements as strings, but could find no reference in my library book regarding how to do that (lots on casting int's a doubles...)
Code:
int _tmain(int argc, _TCHAR* argv[]) {
int comm = 10;
int targ = 5;
int death;
struct AI_WORDS
[Code]....
View 2 Replies
View Related
Jul 1, 2014
Using a for loop, construct two 100 element arrays, x and y, such that element i of x stores the value sin(2*pi*i/100)) and the corresponding element of y stores cos((2*pi*i/100)). Print the values stored in the elements of x and y as you calculate them.
I have attempted to solve it but I'm not sure why the value 0 is only being printed, maybe I haven't assigned sin(2i/100)) and cos((2i/100)) to the arrays properly?
Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main () {
[Code] .....
View 3 Replies
View Related
Dec 17, 2014
int arr[4][5];
for (int(&row)[5] : arr){
for (int &column : row){
} }
Why do we name it row instead column?
int arr[row][column]
Wouldn't this be like
int arr[4][5];
for (int(&column)[5] : arr){
for (int &row: column){
}
It just seems funny to me because we use row[5] which should be 4 if we meant row? Or did I read it wrong in C++ prime !?
View 2 Replies
View Related
Apr 15, 2013
I'm trying to write a function that takes a 32bit address and a data to store at this address.
I'm wanting to take the 32 bit memory address eg 0x12345678 and split it
into 4 x 2 bytes
12, 34, 56, 78
then each of the 4 entries is at most a 256 entry array.eg
FF, FF, FF, FF
So in this example, 0x12 points to 0x34 in the second array, which points to 0x56 in the third array, which finally points to 0x78 in the last array. This last array holds the actual data.
After successfully doing 0x12345678, say I might get a read for 0x1234AABB. So, the first and second pointers already exist, but I then have to create and write to dynamically created arrays.
The arrays need to have all entries set to NULL so that i know whether to follow the pointers to overwrite a previously entered value or create new arrays and pointers.
It all looks good and simple in the pseudo code I've written up but I'm having trouble coding it. I'm currently trying to deal with the first entry case, ie all array elements are NULL, but I'm getting confused with the pointers and creation of new arrays.
void cpu::store(unsigned int mem_add,unsigned int mem_val) {
int first = (mem_address&4278190080)>>24;
int second = (mem_address&16711680)>>16;
int third = (mem_address&65280)>>8;
int fourth= (mem_address&255);
[Code] .....
A1 has been declared as
int* A1[256] ;
View 3 Replies
View Related
Jul 24, 2013
like for example if
Num1[0]=2
Num2[0]=3
this is not working x= Num1[0] + Num2[0];
is there any other way ?
View 11 Replies
View Related
Nov 13, 2013
Basically on this assignment I must write program that inputs two positive integers of at most 100 digits and outputs the sum of the numbers into an array. The two positive numbers must come from different arrays and the sum has to be stored into another array.
View 2 Replies
View Related
Jul 23, 2013
For example if we have
array1[5]= {1,2,3,4,5}
and
array2[5]={2,3,4,0,7)
how do you sum them up as 12345 + 23407 . And when i say sum I mean normal mathematical sum.
here is my code:
int main () {
string str1;
string str2;
[Code].....
View 4 Replies
View Related
Mar 11, 2013
I need to find S and how did you find S in N is 4
#include <iostream>
int main () {
int n,i,s;
cout<<"Put the number of n"<<endl;
cin>>n;
s=0
for (i=1;i<=n;i++)
s=s+i
cout<<"S is<<s<<endl;
return 0
}
View 8 Replies
View Related
Feb 12, 2014
Compiled on turbocpp 4.5.....error is that the final merged array is much bigger with garbage values...
Code:
//cpp program to concatenate 2 arrays
#include<iostream.h>
#include<conio.h>
//the class
class array
[Code] .....
View 6 Replies
View Related
Apr 16, 2013
how to make the functions for b, c, d. if possible running through on how to would be more beneficial than just giving me the answer.
Global warming. As part of a global warming analysis, a research facility tracks outdoor temperatures at the North Pole once a day, at noon, for a year. At the end of each month, these temperatures are entered into the computer and processed. The operator will enter 28, 29, 30, or 31 data items, depending on the month.
You may use 500 as a sentinel value after the last temperature, since that is lower than absolute 0. Your main program should call the read_temps(), hot_days(), and print_temps() functions described here:
(b) Write a function, read_temps(), that has one parameter, an array called temps, in which to store the temperatures. Read the real data values for one month and store them into the slots of an array. Return the actual number of temperatures read as the result of the function.
(c) Write a function, hot_days(), that has two parameters: the number of temperatures for the current month and an array in which the temperatures are stored. Search through the temperature array and count all the days on which the noon temperature exceeds 32F. Return this count.
(d) Write a function, print_temps(), with the same two parameters plus the count of hot days. Print a neat table of temperatures. At the same time, calculate the average temperature for the month and print it at the end of the table, followed by the number of hot days.
View 1 Replies
View Related
Jan 12, 2015
Code:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int main() {
int a[10],b[10],c[10],i,j,k,n,m;
printf ("Enter the size of the first vector: ");
scanf ("%d", &n);
[Code] .....
Now, this is what I've been able to do so far, i know it's very basic but I just started learning programming! I tried different methods found on internet but none of them work for me. I want to find the intersection of arrays a & b then put them in array c(or just display them?)
View 6 Replies
View Related
Feb 2, 2013
I am attempting to assign "randomChoice" as the array index of the "listOfWords" array then copy "listOfWords[randomChoice] to "selectedWord". I am not sure if it is that I do not fully understand the use of strcopy() or something wrong with my arrays.
This is my error:
Code:
hangman.cc: In function ‘void SelectWord(char (*)[80], int, char*):
hangman.cc:84: error: invalid conversion from 'char' to 'const char*' And my code:
Code: #include <iostream>#include <fstream>
#include <cstdlib>
#include <cassert>
#include <cstring>
[code].....
View 4 Replies
View Related
Jun 29, 2013
This is a function that is supposed to add two different arrays containing 9 items together, but it has a problem when it comes to doing any actual adding.
Code:
int * add_data(int x[], int y[], int z[])
{
int i;
char a[9];
for (i=1;i!=9;i++)
{
printf("%d =x
", x[1]+y[1]);
x[1] + y[1]= a[1];
}
return a;
}
View 5 Replies
View Related
Mar 6, 2015
I have one small doubt in arrays. Is it possible to define arrays like this a[b[10]] ?...
View 6 Replies
View Related
Jun 12, 2013
I'm doing a 1Mb memory dump like this:
Code:
for (int i = 0; i < 0x00100000; i++) {
dump[i] = *(chipmemory+i);
} // i
Then I save the 1Mb "dump" array to a file, and the file contains the data I expect.
The problem arises when I try to write data back to the array beginning at the "chipmemory" pointer:
Code:
unsigned char msga[18] = "SOME MODIFIED DATA";
int address = 172378;
for (int i = 0; i < 18; i++) {
*(chipmemory+address) = msga[i];
address++;
} // i
Is this the correct way to write back to an address 172378 bytes from the "chipmemory" pointer? or is my code broken somewhere else?
View 8 Replies
View Related
Jul 30, 2014
If i want to input (FROM A FUNCTION) information into a struct:
* How do I define/ call/ prototype that function.
* How do I check if that array inside the function is empty?
View 1 Replies
View Related
Dec 24, 2013
So when if you want to change the values themselves for example in an array (just for example) this is valid;
void test(int* test)
{
test[0] += 10;
}
int bob[] {1, 3, 5};
If you did that bob[0] would not equal 11. All well and good right?
Now if you do this?
int sally = 33;
test(sallay);
This wouldn't work at all you actually have to use
void test(int& test)
{
test += 10;
}
how the memory addresses etc. are working here? I don't understand why you need to use & the reference operator if it's not an array? Why wouldn't that still work?
View 3 Replies
View Related
Apr 11, 2013
For example If I have the following . How would I sum each row and column ??
For example
1 2 3 4 5
0 1 3 8 9
View 6 Replies
View Related
Mar 15, 2013
how to use 2D vector instead of 2D arrays?
View 1 Replies
View Related
Apr 8, 2013
I have already defined two arrays:
int songId[15];
char typeOfSong[15]
For my assignment we HAVE to use typedef to declare these. I tried a multitude of combinations using typedef, but then the rest of my code that uses songId and typeOfSong is not valid. How would I set up the correct arrays using typedef?
View 1 Replies
View Related
Apr 29, 2014
Okay, so I am developing a program that does many things. One of the is finding the sum of the third row in an array.
Here is my program
#include <iostream>
#include <string>
using namespace std;
void changeNum (int qArray2D [5][5]);
void printNum (int qArray2D [5][5]);
void calcNum (int qArray2D [5][5], int sum);
[Code].....
View 14 Replies
View Related
Feb 9, 2015
javascript:tx('quote')
void family () {
string father;
string mother;
string kids;
int x;
int y=0;
[Code] .....
How am I allowed to but the 3 strings father, mother and kids in a array?
View 3 Replies
View Related