C++ ::  how To Input Values Into Array Via Functions

Sep 5, 2014

What "int values" is supposed to mean as parameters to these functions? I'm not sure what do with them. Also how to input values into the array via functions. I was trying to but I just don't understand how to connect a user's input to a function to then enter into an array.

// input reads “values” integers from the user to place in the array data. It prompts the user for each value individually with the ordinal position of the value.
void input (int data [size], int values);
// Places the sum of corresponding values from arrays a and b and places the results in array s. The first “values” integers in the array are processed.
void do_sums (int a [size], int b [size], int s [size], int values);

[Code]...

View 2 Replies


ADVERTISEMENT

C/C++ :: Matching Input Value To Values In Array

Apr 1, 2015

I have developed the following code for a PIC18 micro-controller. The object of the program is to compare a input value (presumably from a magnetic swipe card), represented here as scan_id, to a list of valid access ID's represented by the array valid_id. If there is a match the program will drive an output pin high to light a green LED for 20 seconds. If there is not a match the program will drive an output pin high to light a red led for 20 seconds.

The issue that I am having is that when the program is executed, the "else" case for the red LED is always selected regardless of the value for scan_id. If I change the "if" statement from == to = then the case for the green LED is always selected regardless of the value for scan_id.

#include <p18f452.h>
#include <stdlib.h>
#include <stdio.h>
#include <delays.h>
void main () {
TRISA=0xFF; /* Configure PORTA<7:0> pins as inputs */
TRISB=0x00; /*Configure PORTD<7:0> pins as outputs */

[Code] ....

View 10 Replies View Related

C :: Can't Input Values In A Dynamically Allocated Array

Oct 5, 2014

this is my function for allocating memory in 2D array

Code:

#include <stdio.h>
#include <stdlib.h>
int allocate_array(int **array, int *row, int *column){
int i;
}

[code]....

end of allocate_array function and this is my function for asking for the values to be stored in array

Code:

int input_array(int **array, int row, int column){
int i, j;
//ask for the values to be stored in the 2D array
for( i = 0; i < row; i++ ){
for( j = 0; j < column; j++ ){
}

[code]....

why I'm having error here in my input_array() function

Code: scanf("%d", &array[i][j]);

View 2 Replies View Related

C++ :: Using For Loop To Input And Output Array Values

Jan 23, 2014

so i got this piece of code today having some slight errors with it, how its actually done as i want to know where i have gone wrong here is the code .. Using a for loop to input and output array values

*/
#include <stdio.h>
int main(void) {
/* Declare an array of integers */
int Grades[5];
int nCount;
/* Populate the array */
for(nCount = 0; nCount < 5; nCount++)

[Code]...

View 3 Replies View Related

C++ :: Passing Values Into Array Using For Loop From Input File

Jul 5, 2014

I'm trying to pass these numbers into the array using the for loop: 1, 2, 3, 4, 5. I created two files in my project called "inStuff.txt" and "OUTPUTS.txt". I know I have an error at my input in the for loop, which is a bit similar to my problem or something? I'm also on linux using a crossGCC complier(not sure if that makes a difference).

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

[Code]....

View 4 Replies View Related

C++ :: Using A For Loop To Input And Output Array Values Also Calculate The Average

Jan 24, 2014

I have this code that im stuck on what i need to do is Extend the code such that when it starts the user is asked to input values to specify each of the three ranges before moving on to accept and tally the main values how do i do that Using a for loop to input and output array values Also calculate the average

*/
#include <stdio.h>
int main(void)
{
/* Declare an array of integers */
int Grades[5];
int nCount;
int nTotal = 0; /* Declare and initialise the value */
float fAverage;

[Code]...

View 1 Replies View Related

C++ :: Create Simple Input Interface On Console - Allow To Input Values To Variables

Apr 6, 2013

I am trying to create a simple interface on console to allow to input some values to some variables. For ex:

int main() {
double a = 1.5;
double b = 2.5;
double c = 3.5;
string x;

[Code] ....

However, I want these three to display at the same time (now they display one by one), and in the console window I can move the cursor between input place of a, b and c with "arrow key" of keyboard.

View 2 Replies View Related

C/C++ :: Compare Values Stored In First Array To User Inputted Values In Second Array

Oct 19, 2014

Goal: Write a program that compares the values stored in the first array to the user inputted values in the second array.

In order to fix this error: [URL]...

I had to change my array initialization to one with a star in front of it:

char a1[]={"a","d","b","b","c","b","a","b","c","d","a","c","d","b","d","c","c","a","d","b"};
to:
char *a1[]={"a","d","b","b","c","b","a","b","c","d","a","c","d","b","d","c","c","a","d","b"};

I also changed my 2nd array to one with a star in front of it: char *a2[20];

What does this mean exactly? Putting a star in front of an array?

Also, I am now getting an "unhandled exception" when I try to get input for my 2nd array:

cin>>a2[i];

View 3 Replies View Related

C/C++ :: Array Of Functions Pointing To In Class Functions With Arduino

May 3, 2013

At the moment im trying out with pointing to an array of functions. I got this working as following:

typedef void (* functionPtr) ();  
functionPtr functions[2][2]={{do11,do12}, {do21,do22}};    
void do11(){DEBUG_PRINTLN("11");}
void do12(){DEBUG_PRINTLN("12");}
void do21(){DEBUG_PRINTLN("21");}
void do22(){DEBUG_PRINTLN("22");}    
void loop(){
         A=0;
         B=1;
         functions[A][b]();
}  

But now I'm trying to use this to point to a function inside a class so instead of do11, i want to be able to point to Basic.Do11. Somehow this doesnt work and I keep on getting this message:

error: argument of type 'void (Basic::)()' does not match 'void (*)()'

View 2 Replies View Related

C++ :: Functions Which Return Values

Nov 27, 2014

Write a function named cointoss that simulates the tossing of a coin.

When you call the function, it should generate a random number in the range of 1 through 2.

If the random number is 1, the function should display "heads".

If the random number is 2, the function should display "tails".

Demonstrate the function in a program that asks the user how many times the coin should be tossed, and then simulates tossing the coin that number of times.

Report the total number of heads and tails.

View 2 Replies View Related

C++ :: Passing Values To Functions?

Jul 29, 2013

I am trying to get some confirmation about how to pass to functions. If you want to assign default values to certain parameters, and have others defined inside the body of int main(), then the parameters which will have default values go at the end of the list. Is that correct?

i.e. The following code is wrong, because we cannot leave a black in the function call on the third line of the main function. However, if we switch the prototype to void Passing (int a, int c, int b = 1); and the function definition to void Passing (int a , int c, int b) everything will be okay and we can call the function as Passing (a, c).

In brief, we cannot do this EVER:
Passing( a, , c)right?
#include <iostream>
using namespace std;

[Code]......

View 4 Replies View Related

C++ :: Functions Returning Values?

Apr 9, 2014

I have an assignment in my C++ class that is to create a menu based coffee shop program. Here is what I have so far:

#include<iostream>
#include<cmath> //doubt this is needed but i added it just in case
using namespace std;

[Code]....

View 19 Replies View Related

C/C++ :: Why Won't Functions Process New Values

Nov 5, 2014

I was given an assignment where I have to input two points (four integers) on a Cartesian plane from a file and then process it using functions. My professor is very particular so the comments are a bit excessive, but here's what I have.

double radiusFn(double, double, double, double);//4 double values, one for each point. All points are needed for the calculation of distance in this function.
double diameterFn(double);//Only uses one double value - the radius. Both functions below use the same value.
double circumferenceFn(double);
double areaFn(double);
int main() {

[code].....

The file reads:

Quote

1 2 3 4 5 6 7 8 9 10 11 12

View 2 Replies View Related

C++ :: Share Values Between Functions In Same Class?

Mar 22, 2013

Code:

#ifndef CANDIES_H
#define CANDIES_H
#include <iostream>
#include <fstream>
#include <Global.h>
class Candies

[Code]...

Code:

#include "Candies.h"
#include <Windows.h>
#include <iostream>
#include <fstream>
#include <sstream>

[Code]...

When I tested it, the file name in getName() outputted the right file name. However the file name in loadName() does not print out anything in the console window.

I want it to be so that the strings in [I]name_addTXT.c_str() in both functions are equal.

View 4 Replies View Related

C++ :: How To Pass Structure Values Between Functions

Dec 29, 2012

Code:
struct NewPlayer {
int level;
int intelligence;
int damage;
};
int CharacterInfo(NewPlayer MageWizard, int Clevel,int Cint, int Cdam)

[Code] .....

View 1 Replies View Related

C :: Pass Values In Functions And Writing Them To A Txt File

Aug 23, 2013

This code is for fun, and have it doing a lot of what I want it to, just not all. I want random generated to write to a txt file. I tried to use an array but that failed. I wanted to use an array because i am only passing one value. Which makes sense since the random generated function is an int.

I made the fprintf as a comment but hopefully soon it will be able to send the values to the txt file. After that I will tackle the function.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define HIGH 49
#define LOW 1
int random_generated()

[Code]...

View 11 Replies View Related

C++ :: RValue - References As Return Values Of Functions

Aug 13, 2014

I am trying to understand RValue-references as return values of functions. First let's consider a simple function, that transforms a string into upper case letters.

const std::string
toUpper(std::string orig) {
std::transform(orig.begin(), orig.end(), orig.begin(), ::toupper);
return orig;

[Code] .....

It compiles, but I get the output 0 . Here I am wondering why the code above does not move the substr correctly while the code below does (prints out 1):

const std::string&&
no_sense(std::string abc) {
abc = abc.substr(1, 1);
return std::move(abc);

[Code] .....

In both cases abc is a temporary object inside of the function and gets deleted after the function is left. But why does the second version work and the first one does not?

cat.substr(1, 1)

And as my last question. Why doesn't

return std::move(abc.substr(1, 1));

work?

View 3 Replies View Related

Visual C++ :: GetMost And GetLeast Functions Returning Erroneous Values

Apr 5, 2014

After compiling, I cannot understand why my getMost and getLeast functions are returning erroneous values. I've done everything I could think of to try and fix this, Problem and code below.

A local zoo wants to keep track of how many pounds of food each of its three monkeys eats each day during a typical week. Write a program that stores this information in a twodimensional 3 * 7 array, where each row represents a different monkey and each column represents a different day of the week. The program should rst have the user input the data for each monkey. Then it should create a report that includes the following information:

* Average amount of food eaten per day by the whole family of monkeys.
* The least amount of food eaten during the week by any one monkey.
* The greatest amount of food eaten during the week by any one monkey.

Input Validation: Do not accept negative numbers for pounds of food eaten.

Code:
#include <iostream>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;

// Constants.
const int NUM_MONKEYS = 3;
const int NUM_DAYS = 7;

[Code] ....

View 3 Replies View Related

C/C++ :: Accepting Input For Functions?

Apr 7, 2014

how would one Be able to accept input for a function, for example:

#include <iostream>
using namespace std;
int numSubtract (int x){
if (x==1)
return 1;
else
return numSubtract (x-1);
}
int main (){
cout << numSubtract (5) ;
}

how would I be able to have the user input their own number instead of 5 in this example, and then output that?

View 2 Replies View Related

C++ :: Elevate Input Number Without Using Advanced Functions

Oct 9, 2013

Last night I was trying to see if is possible to multiply one number to another without using any given function(like pow) or the multiply sign or whatever. Just using addition and subtract signs (+and -) with a for loop. It worked.

Now I am trying to understand if is possible to elevate one given number (inserted by the user) to another number without using again any function or the multiply / divide/ etc functions. Just add and subtract functions.

View 3 Replies View Related

C++ :: How To Get A Video Recording As Input From Webcam To One Of Program Functions

Mar 25, 2014

I want to write a program that is going to turn on my webcam and then display whatever the webcam is pointing at on the app. But I am more interested in knowing how I can get a video recording as input from the webcam to one of the program functions, because I suppose that is what should happen.

View 1 Replies View Related

C++ :: Input Only Values Between 2 - 7

Jan 4, 2015

I want to input only values between 2 - 7 what is wrong?

do{
cout<<"Podaj wykladnik
";
cin>>b;
}while(b<=2 && b>=7);

View 2 Replies View Related

C :: Functions That Declare Arrays In Function Input Even Though Already Declared In Main

Mar 6, 2015

I have seen functions that declare arrays in the function input even thou the arrays is already declared in main. Why do you do this?

For example:

int ova(int antal, char glosorSv[][MAX], char glosorEn[][MAX])
int main(void)

char glosorSv[][MAX]
char glosorEn[][MAX]

View 2 Replies View Related

C++ :: Output Vowel From User Input - Error With Strings And Functions

Nov 25, 2014

The program is supposed to read in a string from the user and then output the number of each vowel that the string has. My first function is initializing the vectors, and the one that I'm having trouble with is the function used to read the string from the user and save it.

Here's my code:

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;

// FUNCTION PROTOTYPES GO HERE:
void init_vectors(vector<char> & vowels, vector<int> & frequencies);
string read_text(const string & prompt);

[Code] ....

And I'm getting the error:

freq.cpp: In function ‘std::string read_text(const std::string&)’:
freq.cpp:74: error: no matching function for call to ‘getline(std::istream&, const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)’

I'm not too sure if I can't use the function getline here or if there is something wrong with the function prototype itself but I'm pretty sure there isn't an error there as it was given to me.

View 4 Replies View Related

C++ :: Implement Member Functions Of Class Function - Failing To Get Input

Aug 17, 2013

I am supposed to implement the member functions of class Person.

class Person {
public:
Person();
Person(string pname, int page);
void get_name() const;
void get_age() const;

[Code] ....

The code I wrote is below. Where I am struggling is the program does not allow me to input age. Therefore, I cannot test if my temp for age works. It automatically defaults to 0 because it hasn't taken input. Here is my code:

// Program Title: Person function
// Program Description: The program prompts the user for first and last name and age.
// It then prints the output that was provided by the user.

#include<iostream>
#include<string>
using namespace std;
class Person {

[Code] .....

View 13 Replies View Related

C++ :: Print Out All Input Values

Mar 16, 2013

I have a problem with how to print out all the numbers that the user enters the code looks like this so far:

Code:
#include <iostream>
using namespace std;
int main()

[Code] ....

I want the program to print out all the numbers that the user has entered after the program have said the higest and lowest number is ?. But I do not know how to do this I thought it could be something like this:

Code:
cout << input[0];
//or
cout << input[i];
/*

Because i is the number of how many enters of numbers the user can do*/ But that was totally wrong tried to do another "for loop" in the first for loop but that was meaningless because it can't change anything in the first "for loop".

View 7 Replies View Related







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