473,386 Members | 1,842 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Evaluating Expressions

15
How do I go about writing a program that finds and prints the values of result for all even values of y from 2 to 16, using the following formula:
result= (y-1) + (y+4)3
y -
1
y

* the 3 is power to 3
*the denominator means y minus 1 over y, just couldn't get it to stay on the same line.
I just don't know where to start. please help!
Mar 12 '10 #1

✓ answered by Banfa

Expand|Select|Wrap|Line Numbers
  1.                         3
  2.            (y-1) + (y+4)
  3. result=    --------------
  4.              (y-1) / y
You start by working out how to write a loop that will iterate through the even integers 2 - 16. You look in math.h or a reference book for functions that are going to be useful (pow I suggest) and you code your equation probably not on a single line of code.

Remember that for all y > 0 (y-1) / y in integer arithmetic is 0
also remember that divide by (y-1) / y is the same as multiply by y / (y-1)
also remember that for all y > 2 y / (y-1) in integer arithmetic is 1

and finally remember that for multiply by y / (y-1) it is sometimes better to multiply by y then divide by (y-1) rather than calculating y / (y-1)

3 1511
Banfa
9,065 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1.                         3
  2.            (y-1) + (y+4)
  3. result=    --------------
  4.              (y-1) / y
You start by working out how to write a loop that will iterate through the even integers 2 - 16. You look in math.h or a reference book for functions that are going to be useful (pow I suggest) and you code your equation probably not on a single line of code.

Remember that for all y > 0 (y-1) / y in integer arithmetic is 0
also remember that divide by (y-1) / y is the same as multiply by y / (y-1)
also remember that for all y > 2 y / (y-1) in integer arithmetic is 1

and finally remember that for multiply by y / (y-1) it is sometimes better to multiply by y then divide by (y-1) rather than calculating y / (y-1)
Mar 12 '10 #2
joeyke
15
#include <cmath>
#include <iostream>
using namespace std;
int main()
{

double y;

cout<<" Enter an value for y: ";
cin>>y;

double check;
check=(y>0)+((y-1) / y))+((y > 2 y / (y-1));
cout<<" y= ";
cin>>y;

if (check>0)
{
y=(y............);


system ("pause");
return 0;
//i left the y=(y.......); blank because i have no idea what to do there!
Mar 12 '10 #3
whodgson
542 512MB
Go back and reread Banfa`s post
You need a for loop to iterate through the even numbers b/n 2 and 16. Also to use the pow() function from the <cmath>header.
double a = double pow(double(y+4),double 3) or a=pow(y+4,3)
Of course y+4 cubed is nothing more than (y+4)*(y+4)*(y+4).
I would suggest you leave your checks out until later and use if statements to control y values like if(y=0)y=1;
Mar 12 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: Jason | last post by:
Hi, below is example code which demonstrates a problem I have encountered. When passing a number to a function I compare it with a string's size and then take certain actions, unfortunately during...
10
by: Jason Heyes | last post by:
Are the side effects of evaluating expr1 resolved before expr2 is evaluated? if (expr1 && expr2) Thanks.
3
by: Kevin Rollo | last post by:
I'm playing with a generic routine to export data, the concept is to have a list of data driven templates defining what fields to output. Evaluating a simple variable field name in the function...
10
by: John A Grandy | last post by:
What's the proper way to write a validation regex so that all leading and trailing spaces are trimmed before evaluation ? Thanks.
4
by: Wade | last post by:
Hi guys, I am building a string in code that is a mathematical formula, based on a lot of criteria specified by the user. Once the formula is complete, I want to evaluate it to get a result. ...
1
by: kaosyeti | last post by:
is there an easy way to evaluate a calculated control step by step? i have a lot of long expressions in a lot of my controls and if there's an error, tracking it down is a PAIN. excel has a...
4
by: pinkfloydhomer | last post by:
We might use the normal preprocessor something like this #define WIDTH 42 #define HEIGHT 100 #define AREA (WIDTH*HEIGHT) To have "42*100" is inserted in the code whereever AREA is used. But...
2
by: linuxadmin | last post by:
Hello everyone! I evaluate XPath expressions using XPathNavigator and need to know for each result, which line number (or et least file position) it has inside the XML file. Any ideas? ...
4
by: jake | last post by:
Is there a way to evaluate a string expression such as "55/8" to return 6.875? Your help is greatly appreciated. jake
6
by: eureka2050 | last post by:
Hi, I am a PHP coder, recently ran into a bit of a problem trying to evaluate expressions in PHP. I have an expression which is stored in a string variable and when I try to evaluate it, it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.