C++ :: Allowing For User Input Of Equation To Be Evaluated
May 14, 2014
I've written a program that finds the maximum of a function. I now want to change it a little so that instead of evaluating the function y=x^2-7x-18, the program will ask the user to input an equation and then evaluate that equation. I'm really not sure of how to do so.
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
int main() {
int a, b, delta, x, y;
double max= -1.8 * pow(10, 308);
[Code] .....
View 3 Replies
ADVERTISEMENT
Oct 21, 2013
This code is near complete, the only task that is left is allowing the user to input a decimal and then two integers, or automatically using .00 decimal.
The automatic part: /*This is not correct.
printf(".%.2d
", number);
*/
But that does no good for me. Question: Do I have to create a some sort of while loop again, to allow the user to input a decimal followed by integer?
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
int j , i = 0, k = 0;
int number;
[code]....
View 1 Replies
View Related
Oct 30, 2014
I have a small project for school due today but i cant get my head around programming
Ive to create a program where ive to get the values from the user and add them to an equation. I have also to add a selection statement where it will ask for the material being tested which will have its value set in the program.
View 4 Replies
View Related
Mar 13, 2013
Any alternative method to what I'm trying to do if possible (not vectors, though). The error in question is on line 9.
#ifndef _TEST_H_
#define _TEST_H_
const int NUM = 10;
class CTest {
public :
[Code] .....
View 2 Replies
View Related
Apr 15, 2014
I wrote this program:
#include <iostream>
#include <ctime>
#include <ctype.h>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
[Code] ....
LETTER OR '.' ? s
LETTER OR '.' ? f
LETTER OR '.' ? b
LETTER OR '.' ? e
LETTER OR '.' ? a
LETTER OR '.' ? g
LETTER OR '.' ? .
VECTOR : [ SFBEAG ]
SENTENCE ?
But after this i can't write anything. Do you know why? I've never had problems with getline... when i used cin >> it read but only one word. Now it doesn't even let read...
View 1 Replies
View Related
Jun 2, 2013
I've been writing some code and this is part of it:
Code:
...
URLDownloadToFile(NULL, _T("http://something/something.txt"), path, 0, NULL);
return 0;
}
The file gets downloaded successfully but the downloader wont exit (return value 0). So it remains active.
I am sure the problem is URLDownloadToFile()
I am using Visual Studio 2010 Express.
View 6 Replies
View Related
Nov 1, 2014
I am making program that allows the user to determine how big the array size will be and then asks the user to make up numbers to fill the array. Every time run the program on Dev C++ it says "program has stopped working"
Heres My Code:
//Assignment 19 Program 2
#include <iostream>
using namespace std;
int main()
[Code].....
View 3 Replies
View Related
Mar 25, 2013
how to take two variables with values such as a 1; and b 2;. Now you take cout << a + b; and you will get 3, but I want to somehow have a 1; b 2; and c num; then have a + b = c. So what ever I have the user input is for a and be added together will become the value of the c variable.
View 1 Replies
View Related
Oct 18, 2013
This is my code:
Code:
#include <math.h>
#include <stdio.h>
int main(void) {
float a,b,c,root_1,root_2;
printf("Please enter value a from the quadratic equation
[Code] ......
And I keep getting this error:
Code:
/tmp/ccgtUIun.o: In function `main':
assign345.c:(.text+0xc7): undefined reference to `sqrt'
assign345.c:(.text+0xef): undefined reference to `sqrt'
collect2: ld returned 1 exit status
View 5 Replies
View Related
Apr 14, 2013
Write a program that creates the output shown in the Output Layout section below. The program should create 2 points with x and y coordinates as integers, prompt the user to input the x and y values for one of the points and randomly set the other (-99 to 99 range) and output the length of the radius line segment and the area of the circle that radius defines. The program should then end. Include an SDM for the program and any other appropriate documentation.
Special Calculations:
Distance between 2 points equation:
√((p0x – p1x)2 + (p0y – p1y)2) (This requires use of the math library)
Output Layout: (bold text represents user input)
Please enter the location of your first point.
Enter a value from -99 to 99 for your x coordinate: -2
Enter a value from -99 to 99 for your y coordinate: 17
The location of your second randomly set point.
Your x coordinate: 45
Your y coordinate: -89
The length of the radius line segment from point one to point two is 115.
The area of the circle with a radius of 115 is 41546.33.
Other:
int pAx;
int pAy;
int pBx;
int pBy;
View 3 Replies
View Related
Jul 4, 2014
soo quadratic equation solver. output is "x=nan x=nan".
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
//prototyping
double ans_1(double,double,double)
[code].....
View 2 Replies
View Related
Feb 19, 2015
I'm writing an algorithm on a microcontroller in C.
One of the iterations that takes a long time involves the following equation, summing the product of pairs of variables:
signed char VarA;
signed char VarA;
signed long VarA;
Total+=VarA*VarB;
The vast majority of cases, at least one of the variables VarA and VarB will be 0, so nothing will be added to Total.
Is there a way to check for this condition which might give me a performance increase over doing a lot of multiplying-by-zeros?
View 6 Replies
View Related
Feb 3, 2013
I am creating a program that solves the quadratic equation ax^2 + bx +c.
I have this program almost complete except the output of the equation in the function called display_quadratic. I need the program to display the variables a,b,c in the equation ax^2 + bx + c but I am having 2 problems. My first problem is that I cannot get the right addition and subtraction signs for the equation.
For instance, if the program had the values for a,b,c as 2,2,3
it will display 2x^2 2x 3
How can I get it to display 2x^2 + 2x + 3? or if it was negative like 2x^2 - 2x - 3?
My next question is how do I get to not display the coefficients that are 1?
I had an if-else statement but no matter what I created it would overlap with another statement and print out twice. Here is the code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void display_quadratic (float a, float b, float c);
float root1(float a, float b, float c);
[Code] ......
View 2 Replies
View Related
Sep 10, 2013
I am having trouble understanding how this loops would work. Give the function (x*x*x*x) - (10*x*x*x) + (35*x*x) - (50*x) + 24 Write a program that will use bisection method to find the roots of this function. Define lower limit and upper limit (e.g. -1.05 and 6.05) Starting at the lower limit step along the X axis at intervals of 0.1 for H calculating the function values f(x) and f(x +h), then f(x+h) and f(x+2h) until the upper limit is exceeded. If sign of the function value changes this indicates a root between ranges. Apply bi sectional method to this range until root has been found with an epsilon of 0.000001, then continue on until upper limit has been exceeded and all 4 roots found. If the function is within 0.000001 of zero then root has been found therefore no need for bi sectional method.
Code:
#include "stdafx.h"
#include "math.h"
#define H 0.1
#define epsilon 0.000001
double F(double x);
int main(void)
[code]....
So we have a function and a range. Program requires to work along the X axis at 0.1 increments until it reaches a point where the value changes from positive to negative or negative to positive. Then apply bisection method within that range to a given accuracy then print that root. Then continue on X axis until the next change of sign is found.
View 8 Replies
View Related
Jan 22, 2014
How do to calculate the following equation"5+((56+8)/2)" using expression builder
Note: the equation may change "50+((26+8)/12)"
View 1 Replies
View Related
May 11, 2013
I am working on a program to find the value of the current in a coil. This value satisfies the following equation:
y'=sin(2t)-[(ey-1)/(ey+1)]
which is of the form y'=f(t,y)
I know that in order to solve this I need to use the trapezoidal method to solve a differential equation, the formula is:
yn+1=yn+.5*h(f(tn,yn)+f(tn+1,yn+1) where h=tn+1-tn
I have found examples of the standard trapezoidal method but I do not think they will work because of the difference in the formulas.
View 2 Replies
View Related
Oct 7, 2013
This is my code for the quadratic equation. It keeps telling me that my else is illegal since no matching if statement and my else statement is missing a statement
#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;
int main() {
string Name;
[Code] .....
View 3 Replies
View Related
Mar 29, 2013
My program is returning NaN even though the value in square root function is not negative -1*b + ((sqrt(pow(b,2) * -4 *(a*c))) / 2).
x = 10;
y = -1;
z = 1;
Heres the program:
main.cpp:
#include <iostream>
#include "Quad.h"
double x,y,z; // variable x = 'a', variable y = 'b' and variable z = 'c'.
[Code] ....
I would like it return the answer and not "NaN".
View 10 Replies
View Related
Jan 1, 2014
In this simple end-of-chapter problem, the ages of two people are to be compared and determine who's older. The problem I'm experiencing is that the second user name input is being skipped and going straight to the second users age.
So while running the program it looks something like:
What is user ones name?
<input name>
How old are they?
<input age>
What is user twos name?
How old are they?
<input age>
<if statement result>
Here's my code:
Code: #include <iostream>
#include <string>
using namespace std;
int user_one_age;
int user_two_age;
string user_one_name;
string user_two_name;
[code].....
View 9 Replies
View Related
Sep 2, 2012
So I've got this form that a user puts in a numeric value into a text box. This value then has to be placed into a byte string of data so that it can be transmitted over as a packet. Bellow is what I have so far:
Code:
Byte[] OUTBuffer = new byte[65];//Allocate output memory buffer
Byte[] INBuffer = new byte[65]; //Allocate input memory buffer
if (setmSpeed == true)
{
OUTBuffer[0] = 0; //Not used, must be set to 0
OUTBuffer[1] = 0x85; //Command mode
[Code] ....
I've put in red the area where I'm having issues. I've tried different methods and have not been able to get this working yet. It only works if I speciffy the value manually as with OUTBuffer[1] = 0x85;, but I want byte 2 of OUTBuffer[] to be set with what I put in the text box.
View 4 Replies
View Related
Mar 18, 2013
I'm creating a program that should create a structure of a list of people entered by the user; the only problem I'm having is with the %c. When I have it, the loop only occurs once; if I put a %s, the loop occurs up to 25 times, but it doesn't write to the text file. Here is the code:
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
[code]....
View 2 Replies
View Related
Apr 7, 2013
So im working with forks and creating 2 fork processes. One child and parent. What im trying to get the child to ask me for a value. Then the parent would start to figure out the value and keep trying. Once it figures it out its tells them you got it and simply stops the program. I cant seem to get the program to keep guessing and stop when the number is found which sends a sigint. Here's what i have so far.
Code:
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <stdbool.h>
int main() {
int j, i,pid;
[Code] .....
View 2 Replies
View Related
Feb 6, 2013
I have this code here that counts the number of alphabetic letters the user's input,the number of characters total, the number of words and the number of "the" that was used. However now I need to alter the user's input to have two spaces after the end of each period, no spaces between a word or comma and each sentence has to have a capitalized letter and display them at the end. And I'm stuck on the altering part. I briefly started the 2 spaces after each period but it won't display anything.
#include <cstring>
#include <iostream>
using namespace std;
int main ()
[code]....
View 7 Replies
View Related
Apr 25, 2014
I have written a program and i had to pass an array into a function and now i have a variable for the subscript of the array and i was the user to input data, specificlly a string, more specifically first and last name without having to create two arrays, i have to do this with other things in the program as well, here is part of the program:
int addFunc(const int totNum, string city[],string state[],string street[],string name[],
int addNum[],int zip[],int telNum[],double bal[],int dateLp[], int addCount, int accNum, int usNum)//function will add a new account {
int countAf = 1;
if (usNum < 20)
[Code] ....
it should be able to take firstname space lastname
View 5 Replies
View Related
Nov 10, 2014
I need to make a program that takes in a user’s number and keep dividing it by 2 until it is 1.I need to display the division steps ...
I do not know how to keep making it divide by 2 until 1. I tired this but it obviously did not work..
Code:
#include <iostream>
using namespace std;
int main() {
//User Input
int input,total;
cout <<"Enter A Number To Be Divided By 2 Until 1" << endl << endl;
[Code] ....
View 7 Replies
View Related
Apr 21, 2013
since around 2hours im really fighting with the cin command.It doesn't matter what exactly im trying, it's just not waiting for user input and keeps directly using 0 as "entered" value.
int Value;
cout << "Enter a new value: " << endl;
cin >> Value;
cout << "The value has been set to: " << Value;
View 4 Replies
View Related