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


ADVERTISEMENT

C :: Scanning Equations / Functions Into Program

Nov 15, 2014

I have to make a numerical integration program, how I can write my code so that the user is able to write their own function that they want to integrate?

E.g. they would see the message: 'please enter your function' and would be able to write whatever they wanted e.g. 'x +5' then this would then be integrated by the program.

I have already written a program that can integrate a known function but would prefer that the user could choose their own.

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++ :: Math Game Program - Stuck On Input File

Oct 21, 2013

I am making a math game program that simple and need to have a user input a name and then that name.txt is brought up and use variables from the text to add to their score. heres my code kinda long.

#include <iostream>
#include <cmath>
#include <cctype>
#include <string>
#include <ctime>
#include <cstdlib>

[Code] ....

View 10 Replies View Related

C :: Working With Equations

Nov 19, 2013

I need to find out all the possible equations which are same of a given equation. For eg. a+b+c-d and b+c+a-d are same. So if the user inputs a+b+c-d then the output will be all the possible equations that can be formed from the given equation, viz:

a+c+b-d
c+a+b-d
-d+a+c+b

etc

i.e the program should rearrange the operands and operators in such a way that it should give the same result.

View 5 Replies View Related

C++ :: Equations And Intersection Point

Aug 17, 2013

Program which accepts two lines and and determines their intersection point and whether they lie within a circle, also given interactively. I'm racing against time and I've racked my skull to no avail

View 2 Replies View Related

C :: Calculate The Solutions Of Quadratic Equations

Oct 22, 2014

I have a task to find errors in this long line of code in order to correctly calculate the solutions of quadratic equations.

Code:
int main(int argc, char *argv[]) {
int validInput, solution_type;
double a, b, c, root_1, root_2, q;

/***********************
* Input / Validation
***********************/

/* Check numbers of arguments, and read input */
validInput = (argc = 4);

[Code] ....

Is a section of the code (the first section). And as you can probably guess, it goes on to calculate for a > 0 etc...

I dont really understand what the validinput section is saying? And a, b and c are never defined so Xcode is just saying a,b,c,root1,root2 are uninitialized and I also dont know what means. Do I need to define these values?

Code:
int main(int argc, char *argv[]) {
int validInput, solution_type;
double a, b, c, root_1, root_2, q;

[Code] ......

View 9 Replies View Related

C :: Calculate Equations Just Like A Standard Calculator

Oct 23, 2013

The main point of the program is to calculate equations just like a standard calculator but I wanted to do it myself. I don't understand what the problem is right now but I've managed to create a program that asks for both values but somehow it doesn't want to ask for an operator (*, /, + etc). What's wrong with my code that the terminal skips the scanning part for the operator?

Code:

#include <stdio.h>
int main() {
int value1, value2, answer;
char operator;

[code]....

View 12 Replies View Related

C++ :: Determine Roots Of Quadratic Equations?

May 23, 2013

I have given following exercise in my cpp book: Determine the roots of quadratic equations

ax^2 + bx + c = 0

using formula

x = -b +(plus-minus) (root)b^2 - 4ac/2a

i don't now how to write such code...

View 6 Replies View Related

C++ :: Solving Linear System Of Equations Using Threads

Dec 14, 2014

I am trying to write a code that solves a system of linear equations such as A*B=C. My system has a dimension equal to 1600. The matrix A cab be separated into 4 sub matrices and each can be handled by a different thread. I tried to solve this using the following code:

int main() {
int count = 0;
//Inputing matrix A
ifstream matrix;
matrix.open("example.txt");

[Code] ....

Although the above code gives the correct answer, the time needs to find the solution is bigger than that needed without using threads.

View 1 Replies View Related

C++ :: Finite Difference Method For Partial Differential Equations?

Nov 10, 2013

Calculated by the explicit scheme. Produces some very large numbers.

task:

[math] U_t = 3 (1,1-0,5 x) U_ {xx} + e ^ t-1 [/ math]
[math] U (0, t) = 0 [/ math]
[math] U (1, t) = 0 [/ math]
[math] U (x, 0) = 0.01 (1-x) x [/ math]

Need to find a solution with accuracy [math] 0.0001 [/ math] on the interval [math] T = 1 / a ^ *, where a ^ * = max a (x, t) [/ math] Plot graphs of functions [math] u (x ^ *, t), u (x, jt ^ *) [/ math] where [math] x ^ * = 0.6, t ^ * = T/10, j = 1,2,4 [/ math]

explicit difference scheme is as follows:

([math] $ u_t ^ {j +1}-u_i ^ j) / tau = 3 (1,1-0,5 x_i) (u_ {i +1} ^ {j}-2u_i ^ j + u_ {i -1} ^ j) / h ^ 2 + e ^ {t_j} +1 $ $ [/ math]

code of the program:

int main ( void ) {
setlocale(LC_ALL, "rus");
int I = 10, J = 30, i, j;
double T = 1.0/ pow(3.3, 0.5), h_x = 1.0/ I, h_t = T/ J, epsilon = h_t + pow(h_x, 2), c;
double **u = new double *[I + 1];
for (i = 0; i <= I; i++) u[i] = new double [J + 1];

[code]....

displays the following:

[URL]

View 2 Replies View Related

Visual C++ :: Pthreads - Solve System Of Equations By Gauss-Jordan Method

Dec 15, 2012

I have a problem: solve the system of equations by the Gauss-Jordan methods with pthreads. I have a big matrix A (for example 2000x2000), so i must solve Ax = b. Before I devide matrix to number of threads and each thread must work only with his peace of matrix.

Code:
#include <iostream>
#include "synchronize.h"
#include <pthread.h>
using namespace std;
typedef struct _ARGS {
int thread_count;
int thread_number;

[Code] .....

I write it on Ubuntu, and when I compile [g++ main.cpp -o main -lpthread -lm] the it works good(for example, if in 1 thread I get time_of_working = 10 sec, on 2 threads time_of_working = 5.4, i.e. about 2 times faster ), if I compile like this [g++ main.cpp -o main -lpthread -lm -O3] it is only 1.2-1.3 times faster.

View 1 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/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 :: 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++ :: Comparing Math Operator With A Variable?

Oct 14, 2013

I am trying to compare a math operator with a variable, but i keep getting this error:

postfixDriver.cpp:93: error: expected primary-expression before ')' token.

I'm sure it's probably something simple, but im just not seeing it. Here is the code snippet:

while (strlen(str) != 0) {
split (str, token);
Postfix stack;
double a;
double b;
double answer;
if (atof(token)==0.0)

[Code] .....

View 2 Replies View Related

C/C++ :: Interest Calculator Math Part

Feb 11, 2014

math part.

The equation I need to use is: payment = [(rate * (1 + rate)^number payments ) / ((1 + rate)^number of payments -1)] * loan

Also, the value of rate in the above equation is (interest/12)/100. So 12% annual interest would be 1% monthly interest.

heres my code:

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

[Code].....

View 4 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/C++ :: Define Math Operators As Variable?

Aug 17, 2014

I have to create a program that read two numbers and the math operators +, -, * and /. After that I should print the operation required. But I tried to declare a <symbol> variable as char type, without sucess...

Here goes my script:
float num1, num2, result;
char symbol;
printf("Write two numbers:
");

[code]....

View 1 Replies View Related

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 View Related

C++ :: How Sub String And Math Can Be Used To Make Logical Decisions

Dec 1, 2014

This is an example of how sub string and math can be used to make logical decisions without using if/elses or switches. It works because of this equation

(x + |x|)/x = 2 if x > 0 and = 2 if x < 0.

#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main() {
//declaration of variables

[Code] ....

View 1 Replies View Related

C/C++ :: CodeBlocks Random Math Quiz Generator

Nov 26, 2014

The user will be allowed to pick:

-the number of problems they want to do
-the type of problem (addition, subtraction, multiplication, division)
-the range of numbers for the problems (like 0 to 9, -100 to 100, etc.) [random numbers in the range]

Your program will then display the given number of problems and get the answer from the user. It will tell the user it they are correct or not. If they are incorrect, it will print the correct answer.

After the given number of problems are displayed, the program will give the user the final number correct and percentage correct. The user will be asked if they want to go again. If so, you will reprompt the user for all the information and run again.

I came up with code thinking I was going in the right direction but it doesn't work correctly at all. We have to use functions. My main issue is how do i call variables from another function so all of the functions work together. I repeat I don't understand parameters and calling functions. here's the code:

#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
int get_user_range(int &x, int &y);
int get_random_number ();

[Code]......

View 1 Replies View Related







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