C++ :: Returning A Specific Value?

Jun 8, 2014

How do I return a specific value from a function in order for me to cout it in my int main?

In this case i have solved for a value sigma1 in my function but i want to use the value of sigma1 in my int main also and in other places so how would i do that?

#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdlib>

[Code].....

View 5 Replies


ADVERTISEMENT

C++ :: How To Make Specific Character Show Up Specific Amount Of Times

Mar 5, 2013

How do I make a specific character show up a specific amount of times?

Like I am generating a random number then I need to make "|" show up that many times on the screen.

View 1 Replies View Related

C++ :: TXT File - How To Get Each Specific Value And Add Them All Together

Oct 10, 2013

so I wrote this code in class today and I'm almost done but I need to come up with some sort of equation to add up all the total values. The problem is I am reading data off a txt file so it's all being read as one thing. I don't know how to get each specific value and add them all together. This is my code so far.

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

[Code] .....

here's what's inside the input file

Chisel 50 9.99
Hammer 30 15.99
Nails 2000 0.99
Bolts 200 2.99
Nuts 300 1.99
Soap 55 1.89

I end up multiplying the amount by the price to get the total value as shown in the code above. Now I just don't know how to add the total value of each item to get the total overall value. Also I haven't used invTotal because I want that to be the overall total.

View 1 Replies View Related

C# :: How To Get AI To Look For Specific Buttons

May 5, 2014

Basically I am creating a game and I need the ai to look for specific buttons. At the moment this is the code I have, and what it does is it makes the ai look for any random button that has't already been clicked.

Code:

private Button look_for_spaces() {
Console.WriteLine("Looking for spaces");
Button b = null;
foreach (Control c in Controls) {
b = c as Button; // performs a cast

[Code] .....

Now what I'm trying to do is make the ai go through 4 searches in steps instead of looking for any button. I want it first to look for buttons 1, 2 and 3, if there's a space in any then it will be clicked but if all of them are already clicked it will look for spaces in buttons 4, 5 and 6 and so on if that makes sense. But i'm not too sure how I would do it.

View 3 Replies View Related

C++ :: Function Returning A Value

Feb 20, 2015

I am making a game commonly know as the Hangman using C++.

Now I am trying to add a man in it like this:

0
|/
|
/

Now the problem i am facing is that i am using a check that if a function returns the value 0 "return 0" it means the guess is wrong and it will not update the man but if it returns any value there will be a function called which will update the man.

I just wanna know that how i am going to use the check, the kind of thing that i am trying to use is, in general words "if(function returns a value) then update the man"

int main() {
return match;
}

How are we going to use it in check that if int main is returning 'match' in the check...

View 3 Replies View Related

C++ :: Int Function Not Returning A Value

Jan 22, 2014

This simple little program is not returning a value. The output is

" (string) contains characters" (The number of characters is supposed to display between the 'contains' and 'characters.'

However, if I go to the function and cout the length, the cout in the main body displays just fine.

Here's the main portion :

cout << "'" << input << "' contains "; //Output of character count.
charCount(input);
cout << " characters, including any spaces.
"; //Output of character count.

and here's the function.

int charCount(char *string) {
int length = 0; //Variable to hold the number of characters.
//Gets the number of characters contained in *string and puts that number into length.

[Code] .....

View 2 Replies View Related

C :: Scan Value For Specific Data

Dec 13, 2014

I created a program that will create a file and print a list on it. Here is the code for my program:

Code:
int controlvalue(void) {FILE *controlvalue;
controlvalue = fopen("something.txt", "a+");
/* Series of fprintfs */
fclose (controlvalue);
return 1;}

Here is an example list created by my program:

Code:
[Gifts]Candy=45
Chocolate=32
Toy=128
Robot=754
Doll=1492
Star=21
Phone=72
Skateboard=87
Frame=314
Days=365
Perfume=421

I want to get the value of "Skateboard" on file. So I need to read 9 lines. On the 9th line, the gets() loop will stop. But, what if I only want to get the value of "Skateboard" as integer (87) and not a string? Also, is it possible to scan the value of Skateboard if it's located on a different (or unknown) line?

View 1 Replies View Related

C++ ::  Going To A Specific Line Through Ifstream

Jan 12, 2015

I want to access specific lines in a "*.txt" file. I've heard of seekp() and what not, but don't know how to call them as such.

View 6 Replies View Related

C/C++ :: How To Find A Specific Value In Array

Mar 16, 2015

im having trouble with a function im writing. Its supposed to find the minimum value in an array and return the location of that value heres what i have so far :

int findLowest (int numb []) {
// findLow will hold the subscript of the lowest value in the array
int findLow = numb[0];
int x;
for (x = 0; x < 5; x++){
if (numb[x] < findLow)
findLow = x;
}
return findLow;
}

View 3 Replies View Related

C/C++ :: Overwrite One Specific Sector In HDD

Apr 26, 2015

I want to replace what is in a specific sector with value inside a buffer(dummy value). This code will read what is inside a specific sector. To make sure it works it display what is inside the sector and it displays the chosen dummy value. (the two cout's in main)

What I want to do is to replace the dummy value with what is inside the specific sector. So if the dummy value is '0', I want to replace what is in sector 285 with '0'.

#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <iomanip>
using namespace std;
#define FILE_SHARE_VALID_FLAGS 0x00000007
#define BUFFER_SIZE 512

[Code] ....

View 1 Replies View Related

C/C++ :: Getting Specific Info From A TXT File?

Oct 10, 2014

I'm trying to open a text file with the name "text.txt", for the purpose of only displaying in the console an specific part of the text file. For example, if I got "This is a test [TEXT] This is the message that should display [/TEXT] this is the end of the file", I want only "This is the message that should display" to be the output, the thing is that I can't imagine anyway of doing that. what I should do?

View 5 Replies View Related

C# :: How To Get A Specific List Element

Nov 26, 2014

Here's my list code:

Color.FromArgb(alfa, 0, 255, 255),
Color.FromArgb(alfa, 0, 255, 0),
Color.FromArgb(alfa, 64, 255, 0),
Color.FromArgb(alfa, 128, 255, 0),
Color.FromArgb(alfa, 192, 255, 0),
Color.FromArgb(alfa, 255, 255, 0),
Color.FromArgb(alfa, 255, 192, 0),
Color.FromArgb(alfa, 255, 128, 0),
Color.FromArgb(alfa, 255, 64, 0),
Color.FromArgb(alfa, 255, 0, 0)

How can I get a specific element value from that list?

For example:

if(true)
{
//get "192" from Color.FromArgb(alfa, 255, 192, 0)
}

I don't see the "Edit" option and I've noticed a slight error in the previous post.There should be, obviously, [code]if(true)

{
//get "192" from Color.FromArgb(alfa, 255, 192, 0)
}

I was missing the closing tag.

View 2 Replies View Related

C++ :: Returning A String Array?

Jun 15, 2014

I am trying to return a string array but am only getting the first char. I want to return something like this:

8C TS KC 9H 4S

so I can do my proper checks.

Code:
void PokerFile::splitHands(std::string playerHand) {
for (int i=0; i<=13; i++) {
playerOne[i]=playerHand[i];
}
for (int j=14; j<30; j++) {
playerTwo[j]=playerHand[j];

[Code]....

View 4 Replies View Related

C++ :: Returning Reference Of Vector

Sep 6, 2013

Example code:

Code:
#include <iostream>
#include <vector>
using namespace std;

class A{

[Code]....

I read somewhere, that we can imagine the reference as a pointer to the vector. So, my question is:

Let's assume that instance of class A, named a, was created with new. We call a.getV() to foo and then we call the destructor of a. foo is safe? Is the copy constructor of std::vector called?

View 1 Replies View Related

C :: Returning Value For Item To Variables?

Mar 4, 2014

What the code below is not doing is returning a value for item to my variables (item1, item2, etc..) I'm not sure how I can make a function prototype that will ask for input and basically recycle after going through the program to a new value for each item. I also need to input individual tax for each item. I will also post it in this message:

double tax, item,salesTax;
double cost(double);
double CalcSalesTax(double);
main(){
double total,item1, item2, item3, item4, item5, tax1, tax2, tax3,tax4,tax5;

[Code].....

View 13 Replies View Related

C :: Returning Pointer From Function

Nov 21, 2014

As the title says, i'm using a function which returns a pointer to a struct:

the struct is the following:

Code:
typedef struct POINT
{
uint16_t x;
uint16_t y;
}

Coordinate; the function i'm using:

Code:
Coordinate * Read_XTP2046(void)
{static Coordinate screen;
//calculations to determine the coordinates
screen.x=(temp[1]+temp[2])/2;
screen.y=(temp[0]+temp[2])/2;
// and so on...
return &screen;}

The question is: how do i catch this pointer and make it into a Coordinate struct in which i can read the x and y.

In my main program i would do the following:

Code:
Coordinate cor;
cor = Read_XTP2046();

This does not work, as the function returns a pointer, but how to transform this pointer into a Coordinate struct.

View 8 Replies View Related

C :: Returning Back To Another Function

Mar 7, 2014

Here's a small portion of my program:

Code:
int choice(void) {
char buffer[BUFSIZ];
char answer;
printf("

[Code] .....

I am wondering which is correct to use

Code: return choice();
or
Code: choice();
return num;

View 4 Replies View Related

C :: Returning Values From While Loop

Jul 13, 2013

I am currently doing a bodyfat calculator for a course in school.I'm having a problem getting an output returned from my while loop, which determines the user's gender by user input.My function (outside of main) is currently:

Code:

char gendercheck(gender){
while (true) {
gender = _getch();
if (gender == 'M' || gender == 'm') {
system("cls");
printf("Your selected gender is male.");
break ;

[code]....

My failed tries include "return gender" and "return genderpicked" statements in both the if-functions and the loop itself, which I have deleted since that didn't work. My goal is to get a character stored in gender, so that I can use the information of the user's gender in my main function from this point and onwards.

MY MAIN IS:

Code:

int main() {
char *genderpicked ;
char gender ;
genderpicked = &gender ;

[code]....

View 9 Replies View Related

C :: Returning Function To Array?

Mar 31, 2013

I need to create a function which will print a list from 100Hz to 1000Hz then 1000Hz to 9000Hz. I have created a function in order to calculate and set up the frequency values from 100Hz to 9000Hz using two for loops as shown below. However I am unsure how to return this to the array at the main.

int main(void) {
double Frequency[18];
system ("PAUSE");
return(0); } double Frequency (void)
{
int count;

[Code]....

View 1 Replies View Related

C :: Returning Value From One Threaded Function To Another

Apr 15, 2013

I am using two threads and i want to take value of a function from one thread and use it in other. I am not good at the concepts of threads. Here is the following code:

Code:
void ThreadA(void const *argument){
uint32_t status = I2S002_FAIL;

status = I2S002_Config(&I2S002_Handle0, &I2SConfig_U0C1_A);
if (status != DAVEApp_SUCCESS) {

[Code] ....

So, i want to use the return value of temp_buffer from ThreadB into Thread C and want to put this value to TXBuf in ThreadA...

View 1 Replies View Related

C++ :: Returning Memory Location Of The Value

Jul 12, 2013

In the code below. I believe I am returning the memory location of the value I am looking for. How can get the value?

main.cpp

int choice = 0;
PlayerMenu *newPM = new PlayerMenu;
File *file = new File;
// Menu for loading, creating or exiting the game
choice = newPM->menuChoices();

PlayerMenu.cpp

[Code] ....

I am not sure how to deference the value so I can get at the value instead of the memory location.

View 5 Replies View Related

C++ :: Returning 2D Matrix After Processing

Feb 10, 2014

[URL] ....

typedef double (*Matrix)[imax][jmax];
Matrix xboundary(){
Matrix xx;
double x[imax][jmax];
int i;

[Code] .....

All I want to do is be able to Return "x" in some way.

View 1 Replies View Related

C++ :: Why Function Is Not Returning Integer 1 Or 0

Nov 14, 2013

why the function is not returning the integer 1 or 0 ... We have two arrays A and B, each of 10 integers. Write a function that tests if every element of array A is equal to its corresponding element in array B. The function is to return true (1) if all elements are equal and false (0) if at least one element is not equal.*/

#include <stdio.h>
#include <iostream>
#include <time.h>
using namespace std;
int TEST (int arrayA[], int arrayB[], int j);
int main() {
srand (time(NULL));

[code].....

View 2 Replies View Related

C++ :: Returning Values To Main

Nov 5, 2014

I am working on this program below. The problem I am having is trying to return totalDays to the main. In the numOfDays() function there is a for loop that adds the totalDays (totalDays = totalDays + days). I have just been getting errors in returning the correct amount of totalDays to the main from the numOfDays function.

#include <iostream>
using namespace std;
int numOfEmployees();
int numOfDays(int);
int main() {
int totalDays = 0;

[Code] ....

View 2 Replies View Related

C++ :: Returning Object By Reference

Jan 25, 2014

When returning an object by reference, only the address of the returned-object is returned, and that way we spare pushing a large object into the stack, and also spare time of pushing and popping large object to/from stack.

But what happens when the object that receiving the returned-object, is not a reference, but a 'regular' object?

How is the content of the returned object copied into the receiving object?

See for example in main, wid vs rwid. (I know in the case the returned-object is just one variable, there's no need to return it by reference, but its for simplifying the code).

class Rectangle {
public:
Rectangle(int w=0, int h=0);

[Code].....

View 6 Replies View Related

C++ :: Expression - Value Returning Function

Dec 17, 2014

How is the definition of the term "expression" affected by value returning functions, and why?

View 5 Replies View Related







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