C :: Math Function Using Exponential Growth Formula

Sep 3, 2013

Its a basic math function using the exponential growth formula which is correct but the computer is not outputting the right numbers.

Code:
#include <stdio.h>
#include <math.h>
int main() {
int blanketsquares, num1, num2, blanket,remainder;

[Code] .....

View 6 Replies


ADVERTISEMENT

C++ :: Exponential Power Function

Nov 13, 2013

Main is supposed to be sending values to the power function.Write a prototype and function for calculating powers of numbers.This version should have an integer return type and take two integer inputs, for the base and the exponent. It should do the following:

• handle negative bases
• return an error on negative exponents (we’re not doing those yet)
• handle zero exponents

Call your function from a nested loop in main(), which calls the function using every combination of negative, zero and positive numbers for both base and exponent. This will test your function without the user having to input all the data.Any code which calls the library pow() function will lose half of the assignment points.

#include <iostream>
using namespace std;
int power (int, int);
int main() {
int size = 10;
int test[size];
int base;

[code].....

View 1 Replies View Related

C++ :: Function That Computes Result Of Formula For Two Sets Of Inputs

Nov 14, 2013

I'm currently writing a program and a portion of it needs to have a function that computes the result of a formula for two sets of inputs. It then has to calculate and display the difference between the two results.

I have code that takes the input from the user and converts it to the type that I need. In this case we are talking about latitudes and longitudes that will be converted to degrees, then to xyz coordinates.

View 1 Replies View Related

C/C++ :: Finding The Value Of Sin(x) Without Using Math Function

Apr 14, 2013

How can i solve a problem of sin(x) without using any math.h and only using my own declared function.

#include <stdio.h>
int fact (int a) {
    int i;
    int k = 1;
    for (i=1;i<=a;i++)

[Code] ....

View 3 Replies View Related

C# :: Can't Get Math (Sine) Function To Work

May 21, 2014

I'm having trouble with getting a sine function to work. All variables are defined earlier in the same section. I have the code in a button (where I figured it would go) but I get the following error:

WindowsFormsApplication2.Math does not contain a definition for 'Sin'

For reference, I am using Microsoft Visual Studio Express 2013, and am coding a Windows Forms Application.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

[Code] ....

I've tried other functions as well (abs, sqrt, etc.) to no avail, as Math only seems to pop up with two options: Equals and ReferenceEquals.

View 2 Replies View Related

C :: Math Quiz Program - Multiplication Function

Nov 16, 2014

Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void correctResponse(void);
void incorrectResponse (void);
void multiplication( void ); // function prototype

[Code] ....

// end function multiplication

// It keeps crashing. How do I compile the responses into a grade?

View 5 Replies View Related

C++ :: Compound Interest Formula

Jun 21, 2013

Equation for compound interest. The interest is supposed to be $43.34 according to the book, I am ending up with around $35. The actual equation is amount = principal * (1 + rate/t)^t where t = number of times compounded per year. I still have to go through and clean up all the code I just want the formula working first.

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main () {
float princ, rate, comp, savings, interest, rates, year;

[Code] .....

View 2 Replies View Related

C/C++ :: Quadratic Formula - If Statement Being Ignored

Jan 28, 2014

We are suppose to build a program to do the quadratic formula, which isnt really a issue. my issue is i have a if else loop and my if is being ignored.

what i want it to do is is state that if the (b * /> - 4(a)© is a negative, then it prints out stating it cant do this.

note: i know that i can use the i number system but we have been asked to not too and to do this instead.

here is my code

#include <stdio.h>
#include <math.h>
int main() {
float a, b, c, d, e, f, g, h, i; /* i would love to figure out a way to do this without so many variables*/

[code]....

View 3 Replies View Related

C++ :: Compound Interest Formula Coding

Sep 24, 2014

Im having problems coding this
A = P(1 + r/n)nt

//Declared test cases
float principal = 200000.00, annualInt = 0.03;
float years = 10.0;

float calcInterest1(float principal, float years, float annualInt) {
float interest1;
float nt = annualInt*12;
float A = principal+annualInt;//Accrued Amount
interest1 = (A = (principal*(1+years/100))pow(nt));// A = P(1 + r/n)nt
return interest1;
}

View 1 Replies View Related

C++ :: Creating A Loop To Calculate Formula?

Mar 21, 2014

I am trying to create a code and cannot get the following part to work :

for (int n = 0; n = timesteps; n++)
{
n = n + 0.1 ;
cout<< "timesteps"<< n << endl ; //print time step value =0.1
for (int j = 0; j < nodesinx; j++)
{
T[j][n+1] = T[j][n] + 0.16 * (T[j][n] - 1[n] - 2[T[j][n] + T[j] + 1[n] ; //equation
n= n + 0.1 ;
cout<< "temperature" << T[j][n+1] << endl;
T[j][n+1] = 0.0 ;
}
}

View 1 Replies View Related

C/C++ :: Define The Formula Of Prime Numbers?

Jul 27, 2014

It is possible to define the formula of prime numbers in C++ language?

View 1 Replies View Related

C++ :: Calculating Area Of A Triangle Using Heron Formula

Nov 7, 2014

I need to calculate the area of a triangle using heron's formula. I wrote the code below and i need to modify it so that a user is required to keep entering the three side until he/she decides to stop. If the three sides entered make an invalid triangle, the user is required to re-enter the values until valid triangle is formed. Then the area is displayed.

#include <iostream>
#include <cmath>
using namespace std;
int main(){
double a,b,c=0;
double s,A=0;

[Code] .....

the screen output should like this:

Enter three sides of a triangle: 0 1 2 Error!
Re-enter three sides of a triangle: -1 1 2 Error!
Re-enter three sides of a triangle: 3 4 5 => 6

Continue (y/n)? y

Enter three sides of a triangle: 1 1 2 Error!
Re-enter three sides of a triangle: 6 8 10 => 24

Continue (y/n)? n

Done!

Please note that Continue (y/n)? only displayed after a valid triangle is formed. Otherwise, the user needs to re-enter sides until it's valid.

View 1 Replies View Related

C++ :: Quadratic Formula Loss Of Significance And Simplification

Feb 16, 2015

write codes that could solve a quadratic formula, and my codes are like this:

#include <bjarne/std_lib_facilities.h>
int main()
{
cout << "Enter the coefficients of a quadratic polynomial a*x**2 + b*x +c:
";
cout << " a? ";
double a;
cin >> a;
cout << " b? ";

[code]....

Which runs perfectly, but I have 2 questions:

1. How to simplify these code? On the assignment sheet the professor wrote about using void solve_linear(double b, double c); and void solve_ quadratic (double a, double b, double c);which I currently dont understand how these works. He asked us to write a well-encapsulated (as short as possible) program.

2. These are for extra points: the precision problem of floating numbers: professor asked us to find a way to get the precise answer of it, like this: Enter the coefficients of a quadratic polynomial a*x**2 + b*x +c:
a? 1
b? -20000
c? 1.5e-9
Trying to solve the quadratic equation 1*x*x + -20000*x + 1.5e-09 == 0
Using classical formula: Two roots, x = 20000 and x = 0
Using stable formula: Two roots, x = 20000 and x = 7.5e-14

My guess is that
A. Using code like if(x1*x2=a/c) to check if numbers were approximated.
B. Somehow determine the larger one in x1 and x2.
C. Somehow use that larger one to do something

View 2 Replies View Related

Visual C++ :: Totals Or Formula To Calculate Is Not Working?

Sep 19, 2014

My code is below:

Total Interest ends up as my last Monthly Payment amount instead of adding up all Interest Paid - What am I doing wrong?

Total Paid isn't calculating correcly either - What am I doing wrong?

I suspect both are very similar problems. I've tried several different calculations, but cannot figure this out.

#include <iostream>
#include <cmath>
using namespace std;
double GetMonthlyIntrest (double OpenBalance,double rate);
bool ContinuePgm();
int main () {
double StartingBalance,rate,amount,OpenBalance,IntPmt,TotalInt=0.0,GrandTotal=0.0;

[code]...

View 3 Replies View Related

Visual C++ :: Writing Formula For Standard Deviation?

Apr 17, 2013

How to write a formula for standard deviation but im having a hard time ?

View 2 Replies View Related

C++ :: Lagrange Interpolation Formula - Substitute Values Into Power

May 7, 2013

I did a function for lagrange interpolation formula. However i`m stuck on how do i substitute values into the power. Here is my code snippet :

for(int i=1;i<getSecretShare+1;i++) {
//calculateValue=getSecret+(10*p)+(2 * pow(p,2));
int storeThreshold=getThreshold;
calculateValue=getSecret+(10*i)+(2 * pow(i,2));
calculateFinalValue=calculateValue % 17 ;
cout<<"the calculated value is "<<calculateFinalValue<<endl;
}

The formula that i want to implement is that a + a1x^1 + a2x^2 + a(t-1) ^t-1

I have gotten the substitution of the x value out. However, i am stuck on how do i calculate the values according to the threshold which the user keys in. For example if the user keys in 3.

It will into account the no. of shares to generate which is for example 5 in this case, then it will then take into account the threshold keyed in , which is 3, i will then calculate using the formula using the no. of shares and also threshold.
if the threshold is 3 and the number of shares to generate is 5. I should have the following:

y(1) = 13 + a1(1)^1 +a2(1)^2
y(2) = 13 + a2(2)^1 +a2(2)^2

the power depends on the threshold which is t-1, 3-1 =2

So I will have to generate two a values based on that and also calculate them according to the power that is dependent on the threshold the first value being to the power of 1 and the 2nd being to the power of 2 if the threshold is 4.

Then I will generate 3 a values and then calculate them :

y(1) = 13 + a1(1)^1 + a2(1)^1 + a3(1)^3

and so on..

View 4 Replies View Related

C/C++ :: Built In Formula For Calculating The Range Of Float And Double?

Oct 26, 2013

I want to get the direct formula for calculating the range of double and float datatypes in c,if any.

View 1 Replies View Related

C :: Find Factorial Of Any Number Greater Than Zero And Use Gosper Formula To Approximate It

Feb 24, 2013

I was given a question in my programming class to create a program to find the factorial of any number greater than zero and to use Gosper's formula to approximate it.

Code:
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
double equation(int n);
int

[Code] ....

View 2 Replies View Related

C/C++ :: Making Offsets - Addressing Formula Of Straight Forward N Dimensional Array

Apr 12, 2014

I know how to make offsets/addressing formula of a straight forward N Dimensional array but how to make an offset and a storage allocation space for something tricky like:

1. A lower and upper triangular matrix?
2. A band matrix?
3. Making an offset for ragged arrays which have different row lengths?
4.A upper/lower triangular matrix using ragged arrays?

This is not for an assignment but preparation for an exam. I don't know how to go about on finding these out.

View 14 Replies View Related

C :: How To Write Powers Without Using Math

Sep 22, 2014

How would one write 3^i without using .math? (i being numbers 0-9)

More specifically, this is what I have:

Code:

#include <stdio.h>
#include <stdlib.h>
int main(void) {
int x, n, answer1, first;
x = 3;
n = 10;
first = 1;

[Code]....

And this is what I want it to produce:

1 0 1.0
3 1 0.333333343
9 2 0.111111112
27 3 0.037037037
81 4 0.012345679
243 5 0.004115226
729 6 0.001371742
2187 7 0.000457247
6561 8 0.000152416
19683 9 0.000050805

I believe I am only having troubles with the first column,

View 10 Replies View Related

C++ :: Inserting Math Functions From GUI

Feb 8, 2013

I have a problem with entering math functions in my Bisection method algorithm program. I just don't know how can I make the function that I enter in my GUI app to go from the GUI to the loop and find the root.As far as I googled I only find codes that you need to pre-enter a function in the double/float.

For example:I have a function f(x) = x^3 - cos(x) - x - 3; and I want to enter that function trough the GUI i made in c++..So this is the main code.

#include "bisection.h"
#include "ui_bisection.h"
#include <QFile>
#include <QString>
#include <math.h>
#include <algorithm>
bisection::bisection(QWidget *parent) :

[code]....

View 11 Replies View Related

C++ :: Math Formulas Using Variables?

Mar 21, 2013

Working on a program that converts infix to postfix math formulas. Ive successfully converted the infix to a postfix notation but now i am having trouble solving the equation from the postfix form. Im trying to set a result equal to three variables as shown below:

result = op1 ch op2;

where op1 and op2 are numbers and ch is the operator (+-*/) depending on what the user entered into a string. The error im getting is that it expected a ";" before postfix so clearly it doesn't understand what im trying to do. how to put the answer from op1 ch op2 into result.

View 4 Replies View Related

C :: Calculate Value Of Math Expression Using Strings

Nov 4, 2013

Here is my objective: Write a c program that calculates the value of a mathematical expression comprised of positive numbers and the operations "+" and "-" . Specifically, first prompt the user to input an expression, read itin as a string, and then print the value of the expression. You may assume that the expression does not contain spaces, maximumsize of the expression (including digits and operators) can be 20,and that all numbers are single digit numbers.

Note that, the digits would be read in as characters; you will need to translate them to numbers (recall the ASCII table). Implementation Requirements:

Write a function called "evaluate" that takes as input a mathematical expression(as a string) and returns the value of the expression. The prototype of the function is: intevaluate(char expr[]);

Sample Output:
Input: 4+2-1+7 Output:12

Code:
int main()
{
char expr[21];
int a,ssum;
printf("Input: ");
scanf("%20s", expr);

[Code] .....

the program runs, but the output is not coming out correct.

View 11 Replies View Related

C :: Trapezoidal Rule - Math Library

Mar 22, 2013

I am new to c programing and I had spend 2 days on a program and I can't fix the error:

Code] ....
gcc Test.c -o Test.exe
/tmp/ccZkbk0V.o: In function `f':
Test.c:(.text+0x2f): undefined reference to `sqrt'
collect2: ld returned 1 exit status

Tthe program I am working in is:

#include <stdio.h>
#include <math.h>
int f(int x){
return (sqrt(4.0 - x*x));

[Code] .....

View 2 Replies View Related

C :: Date Math Using Standard Libraries?

Dec 22, 2013

Is there any way to do date math using standard C libraries? I looked around in the time.h but didn't see what I needed.

What I need to do is be able to add a certain number of minutes to a date and have it give the current date/time. For example, add 15918765 minutes to 01/01/1980 00:00 and have it tell me 04/07/2010 4:45PM. I really don't want to write this myself or go platform-specific.

Does this exist somewhere or am I SOL?

View 13 Replies View Related

C :: Program That Solves Math Equations

Apr 30, 2013

I wrote a program that solves an equation of two numbers, but in addition to that, I want it to be able to continue to solve longer equations. Ex: ( solves 2 * 4, or 2 * 4 - 5).I want to put this part of the program's result into a variable and go from there. How do I place the result of the calculation into a variable, and where would it go?

Code:

#include <stdio.h>
#include <string.h>
int main(void) {
int a;
scanf("%d", &a);
char s[2];
scanf("%s", s);
int b;
scanf("%d", &b);
}

[code]....

View 4 Replies View Related







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