C :: How To Create Functions Such As Floats

Sep 16, 2014

I am new with C programming and trying to learn how to create functions such as floats. But for some reason when I try to compile this program the compiler will tell me Weight() is not a function.

Code:
#include <stdio.h>
float Weight(float Mass, float g)
{
float Weight = 0;
g = 9.81;

[Code] ....

View 3 Replies


ADVERTISEMENT

C :: How To Create Functions With Arrays

Jun 12, 2013

how to create functions with arrays :/

You have to write a single C program that creates a one dimensional array of size MAX(to be declared as a declarative constant using directive #define MAX 10), initializes its elements with a given value using the function InitArray, then populate the array with some random numbers between 1 and MAX inclusive, and finally search the array for certain keys.

The structure for this C program is as follows:

int main() {
//array A to be locally declared here
int
size = MAX;
}

[code]....

View 3 Replies View Related

C++ :: Create Two Threads Calling Even And Odd Functions

Mar 1, 2013

I want to create two threads which will be calling even and odd functions where even function should print even number and odd function should print odd number.Can it be possible with condition variable? What is the code in both the cases i.e. two separate function and with condition variable.

View 6 Replies View Related

C++ :: List Of Functions That Can Create A Unique ID

Nov 4, 2014

I'm working on a list of functions that can create a unique ID for a computer. Here's what i have so far:

GetAdapterInfo();
RegOpenKeyEx();
GetVolumeInformation():
CoCreateGUID();

Are there any other functions that do this?

View 1 Replies View Related

C :: How To Printf Floats

Jan 30, 2013

I am having a hard time with some of my homework, specifically regarding how to printf floats. I can't seem to print the number i want out using float, it just becomes a jumbled mess.

Code:
#include <stdio.h>
#define TICKER "LRCX"
#define PURCHASE_DATE "01/02/13"
#define SELL_DATE "01/30/13"
#define INVESTMENT_AMOUNT "10,000.00"

[Code] .....

Thats the code I currently have, I've probably tried everything to get the number to come out, but I just cant seem to figure it out. It should look like this, but with different numbers and stock:

Stock: MCD Buy Date: 01/02/13 Sell Date: 01/29/13 Buy Share Price: $89.40 Sell Share Price: $91.50 Shares Purchased: 111.86

Amount of Investment: $10,000.00 Value of Shares Sold: $10,234.90 Amount of Gain/Loss: $234.90 Percent Gain/Loss: 2.35%

However, this is how mine turns out:

Code::Blocks
Enter share purchase price for LRCX=>23
Enter the selling price for LRCX=>23

Stock: LRCX
Buy Date: 01/02/13
Sell Date: 01/30/13
Buy Share Price: -1.#R
Sell Share Price: -1.#R
Shares Purchased: -1.#R

Amount of Investment: 10,000.00
Value of Shares Sold:-1.#R
Amount of Gain/Loss:-1.#R
Percent Gain/Loss:-1.#R%

Process returned 0 (0x0) execution time : 2.864 s
Press any key to continue.

View 3 Replies View Related

C++ :: Comparing Two Floats Ranges?

Dec 24, 2014

I'm trying to compare two float ranges and it seems to be a hit and miss. I'm trying to use a object origin and dimensions comparing it to another set for collisions.

View 12 Replies View Related

C++ :: Adding Two Floats - Summation?

Jun 27, 2013

I am very new at c++ and ran into this problem.

pairPercentage = ((float)tempPair/hands) * 100;
flushPercentage = ((float)tempFlush/hands) * 100;
totalPairPercentage = pairPercentage + totalPairPercentage;

is there something I should be awarded of when adding two float(s) ? because totalPairPercentage will always return pairPercentage, not its summation.

also did (totalPairPercentage += pairPercentage);

View 3 Replies View Related

C/C++ :: Can Use Modulo To Compare Two Floats?

Nov 6, 2012

Can we use modulo to compare two floats?

View 3 Replies View Related

C++ :: How To Get Average Of Floats From A Vector

Apr 24, 2012

Say I have a std::vector of size 10 of float. This will be a windowing average, as each cycle I need to remove the oldest element and add a new element. I figured vector was good because I can pop_front() then push_back(). Is there any clever way to get the average of the vector without using a for loop?

View 5 Replies View Related

C++ :: Converting Integers Into Floats?

Mar 14, 2012

how do you convert integers into floats / I remember there is something like ftoi, I am looking into something handy like the std

View 6 Replies View Related

C++ :: Getting Unexpected Outputs For Bitfields And Floats

Aug 7, 2013

I'm getting unexpected output in 2 different cases. The 1st deals with bitfields. The C++ standard has this line about integral promotions:

An rvalue for an integral bit-field (9.6) can be converted to an rvalue of type int if int can represent all the values of the
bit-field; otherwise, it can be converted to unsigned int if unsigned int can represent all the values of the bit-field.

If the bit-field is larger yet, no integral promotion applies to it. If the bit-field has an enumerated type, it is treated as any other value of that type for promotion purposes.

This sounds like the value of a bitfield will always be treated as a signed int if the signed representation of the value will fit in the bits. This seems to hold true for my C compiler, but not my C++ compiler.

I tried storing a small negative value in a bitfield that has enough bits to store the sign bit and the value. But when I print out the bitfield, I always get a large number

In the example code below, I expect the output:

Code:
foo.x = -1
foo.y = -2
foo2.x = 31
foo2.y = 6
foo3.x = -1
foo4.x = 4294967295 But I get: Code: foo.x = 31
foo.y = 6
foo2.x = 31
foo2.y = 6
foo3.x = -1
foo4.x = -1 -------------------

The other issue I'm having is sort of similar. I'm trying to store 4294967295 into a float, but when I print it out, I get 4294967296. i've tried storing a few other large values like this and what's printed out is rarely the value I stored. I thought it might be because of some int to float conversion, so I tried 4294967295.0. Still no luck. Then I remember that defaults to a double so maybe that's the issue so I tried 4294967295.0f. Still no luck. Why can't I store the correct value here? I don't think it's an IEE format thing since I can use these values as floats on a calculator program.

The example code showing both issues is below.

Code:
#include <stdio.h>
typedef struct {
signed char x : 5;
signed char y : 3;
}my_struct_t;

[Code] .....

View 11 Replies View Related

C++ :: Can't Read Floats Into 2D Array From File

Apr 11, 2014

I can't get the values correctly parsed.

Code:
float **get(int sizeX, int sizeY) /* Allocate the array */ {
float** ary = new float*[sizeX];
for(int i = 0; i < sizeX; ++i)
ary[i] = new float[sizeY];
return ary;

[Code] ....

test.txt (without the comments).

Code:
2 3 // columns and rows of 2D array
0 0
1 1
2 2

View 3 Replies View Related

C++ :: Dice Simulator - Floats Rounding Up

Oct 28, 2013

I made this dice simulator which basically throws the dice 1 million times and outputs the frequency and percentage average for each side (1 to 6).

Everything is working fine, except my averages (floats) seem to be rounding up, causing 4% being "unassigned" at the end of the million rolls. I'm outputting with a setprecision of 2, but I only get 0's and no fractional numbers.

View 5 Replies View Related

C++ :: Dividing Two Floats Not Giving The Required Quotient

Jan 9, 2014

Im using the remquo function in the cmath library as follows:

int quotient;
double a = remquo (10.3, 4.5, "ient);

This gives the correct remainder (a = 1.3) and quotient (quotient = 2).

Infact about 50% of the answers are right when I play around, however, trying something like:

int quotient;
double a = remquo (2.25, 1.5, "ient);

yields an incorrect quotient of 2 and remainder of 0.

I do think this has something to do with float arithmetic. I recall tinkering with the float number 0.500 and that the CPU actually saves it as 0.50000000000000231. However if my suspicion of float arithmetic as the suspect is correct, I do not understand why a tenth decimal would make such a drastic difference as changing the quotient result.

View 10 Replies View Related

C/C++ :: How To Access Linked List Functions From Stack Class Without Functions

Mar 20, 2014

I'm a little confused by my programming assignment this week. I've been working at it Wednesday and I've made progress but I'm still confused as to how I'm supposed to do this. The class I made is called Stack, and it's derived from a template class called StackADT. We also utilize a class called unorderedLinkedList, which is derived from a class called linkedList.

We're supposed to implement all of the virtual functions from stackADT in the Stack class. The Stack data is stored in a an unorderedLinkedList, so what I'm confused by is how to implement a few of the Stack functions because there are no functions in unorderedLinkedList which we could call to manipulate the data.

As you can see from my attached code, I'm really confused by how I'm supposed to implement the pop() and top() functions, and I also think my initializeList() function is wrong. We don't have any similar functions in unorderedLinkedList to call, so I'm at a loss of how i'd access my unorderedLinkedList. My initial thought was to call the similar functions in the class that unorderedLinkedList was derived from, linkedList, but I'm unsure of this is what we're supposed to do, or if theres actually a way to access my unorderedLinkedList without having to use the functions from the base class.

NOTE: We're not allowed to modify stackADT, unorderedLinkedList, and linkedList.

Stack.h

#include "stackADT.h"
#include "unorderedLinkedList.h"
template<class Type>
class Stack: public stackADT<Type>{
template <class T>
struct nodeType
{
T info;
nodeType<T> *link;

[Code]...

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 :: Create Function To Create A Dynamic Array That Fill With Randomly Generated Integers From 0 To 50

Oct 26, 2013

I have a struct called Array and I'm to create a function to create a dynamic array that's fill with randomly generated integers from 0 to 50 (inclusive) and a function to destroy the array for freeing its memory. Below the code that I have written so far.

Code:

* Struct */
typedef struct {int *pArray; //the dynamic array
int length; //the size of the dynamic array}Array;
/* Function to create a dynamic array */
Array *initializeArray (int length) {int i;
}

[code]....

View 7 Replies View Related

C# :: Create Project That Create Automated Backup Of File

Apr 10, 2014

I need to create a project that create a automated backup of a file.

i will get the file from C:/Folder/file.exe and move for a other created folder, but.. in every time that user make this backup, a folder will be created with year, month and date, like: C/Folder2/2014/April/16:42/file.exe.

View 4 Replies View Related

C++ :: Create Binary Search Tree Template To Be Used To Create AVL Tree

Feb 10, 2013

For my data-structures class, I am attempting to create a binary search tree template to be used to create an AVL tree. I've written a Generic_Tree template for the BST to inherit from, and before I jump into implementing the AVL tree I'm testing the BST member functions. Everything was compiling fine until I added the BST insert() function. Now, I'm getting the following error message from my linker:

undefined reference to 'BST<void>::insert(int, void*)'

Stemming from the call in main line 16.

my makefile compiles with:
g++ -Wall -g Generic_Tree.cpp BST.cpp barfing.cpp main.cpp

Generic_Tree:

template < typename NODE_DATA, unsigned MAX_KIDS >
class Tree {
protected:
struct NODE {
NODE_DATA* contents;
Tree* child[MAX_KIDS];
Tree* parent;

[Code] ....

I'm use to c and havn't used classes or templates before (except for declaring instances of them). The whole syntax is mystifying to me,.

View 4 Replies View Related

C :: Getting Used To Functions

Jul 24, 2013

So In my studying of C I am starting to come across more programs with functions in them.This particular program asks for two numbers, and calculates the sum of all the squares of the two numbers and the numbers in between them. I am confused about the get_int() function.

Code:

/* checking.c -- validating input */
#include <stdio.h>
#include <stdbool.h>
int get_int(void); // validate that input is an integer
bool bad_limits(int begin, int end, int low, int high); // validate that range limits are valid
double sum_squares(int a, int b); // calculate the sum of the squares of the integers a through b
}

[code]....

So in that get_int() function, it's pretty simple if scanf returns 1, otherwise... another while loop call the getchar() function, which is assigned to the variable ch. So say I enter 'a' for the lower limit, this is what happens:

Code: Enter the limits (enter 0 for both limits to quit):
lower limit: a

a is not an integer. It seems as if getchar() somehow "got the character" from scanf(). There's no way that getchar() could have been simultaneously reading my input, because that function is not even called until scanf has already not returned 1. So I'm confused how that happened. I was under the impression that getchar() got input from the keyboard, which would lead me to think that I would be prompted to input something again when getchar() is called, before putchar() prints the scanf input. But this is obviously not the case.

Also, I'm curious about that comment beside putchar(ch) that says //dispose of bad input. I recall a long time ago on these forums, someone told me something about how once scanf has read input, that input is like... stuck to scanf.. So does putchar() not only print the input from scanf/getchar, but also unload it from scanf, so to speak?

View 4 Replies View Related

C++ :: Get And Set Functions

Feb 1, 2014

i'm stuck with functions

#include <iostream>
#include <functional>
using namespace std;
template <typename T>
class property

[code].....

the code works like a charm. but imagine that i need more with Get and Set functions, how can i connect them to the T PropertyValue on class property?

View 12 Replies View Related

C++ :: How To Get A Set Of Functions To All Use The Same Template

Dec 11, 2013

I'm getting tired of writing Code: template <typename T> everywhere.

Is the only solution to encapsulate all my desired functions in a templated class?

View 7 Replies View Related

C++ :: How To Declare Functions

Aug 19, 2013

How to declare functions in C++

View 1 Replies View Related

C :: Use Of Functions In Top / Down Approach

Mar 25, 2014

I'm getting a bit lost in calling functions correctly. The assignment says to, reprogram this assignment using functions and include the additional features identified below -

Design your program so the main function invokes/calls functions to perform the following tasks:

4) sort the arrays in ascending order by student ID number

Here's what I've got thus far and I'm confused cuz I might be calling my function incorrectly.

Code:
#include <stdio.h>
#define MAX_ENTRIES 50
void s_ID (int student_ID[], int test_score[], char char_val[]);
int main (void) {

[Code] .....

View 7 Replies View Related

C :: Adding New Functions

Jul 3, 2014

I am new to c and I have come across a problem when adding other functions to a programme and printing the values. The question I am attempting to solve is :

The following function computes ex by summing the Taylor series expansion to n terms. Write a program to print a table of ex using both this function and the exp() function from the math.h library, for x = 0 to 1 in steps of 0.1. The program should ask the user what value of n to use.

double taylor(double x, int n) {
int i;
double sum = 1.0;
double term = 1.0;
for (i=1; i<=n; i++) {
/*Or we could have written: */
term = term * x / i; /* term *= x / i; */
sum = sum + term; /* sum += term; */
}
return sum;
}

My code is

Code:

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
/*Taylor series for e*/

[code]....

code prints out the values for exp, but it gets stuck in the Taylor function and I'm not sure how to solve it.

View 2 Replies View Related

C :: Passing Into Functions

Feb 18, 2013

forget everything from before. It came out of confusion regard the supplier functions. dis_s() and read_s() the part functions work and are not any different really.

Code:

#include <stdio.h>#include <stdlib.h>
#include <string.h>
#define MPS 10 //Max Part Size
#define MSS 10 //Max Supplier Size
}

[code]....

when I run the dis_s() function it just prints out garbage until it segments. starts with a bunch of 0 and newlines until it starts printing locations on my computer...... it worked on campus with debian and I only copied it from gmail to my computer so I really don't understand whats up(im on mint).

View 7 Replies View Related







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