My codes works great . No more errors.
I removed line 57 & 58. I thought that I had to do this to pass the value, but what I needed to do was just call my calc function. I changed the code to divide by 2.0 instead of interger 2 (I always forget to do double). Lastly, I created a new variable ‘perimeter’ to store the perimeter value. And result of ‘s’ is stored in ‘s’.
Thanks for the input.
User Profile
Collapse
-
The passing by reference is working. I tested random data and I don't understand why some works and others produces incorrect results.
Data tested:
5, 9, 7 = perimeter of 21 and area of 12.247 (correct)
5, 6, 9 = perimeter of 20 and area of 14.142 (correct)
9, 7, 3 = perimeter of 19 (this part is correct) and area of 0.000 (incorrect)
5, 8, 12 = perimeter of 25 (this part is correct...Leave a comment:
-
Function call - results not consistent
Hello. My lab compiles with no problems, but the results are inconsistent. Using 2,2,2, as test data, the result is correct, perimeter of 6.000, and area of 1.732. However, when I try to use 8,5,12, the result is perimeter of 24 (should be 25), and area of 0.000 (should be 14.52
The lab specifies that we store the result of "s" and '"area" in reference parameters s and area.
Any input would... -
pyramid replied to Help with apppproximate value of pi = sqrt(6* (1/(1)2 + 1/(2)2 + 1/(3)2+ 1/(4)2 + 1/(in CGot it.
A big thanks to all of you.
I modified the codes based on your input and it worked!. Thanks again.Leave a comment:
-
pyramid replied to Help with apppproximate value of pi = sqrt(6* (1/(1)2 + 1/(2)2 + 1/(3)2+ 1/(4)2 + 1/(in CThis is the revised codes. I am still unable to get the correct results.
Code:for (count =1; count <= terms; count++); { pi = (1.0 /(terms * terms)); } pi = sqrt * pi; pi = pi * 6;
long int terms
long int count;
...Leave a comment:
-
pyramid replied to Help with apppproximate value of pi = sqrt(6* (1/(1)2 + 1/(2)2 + 1/(3)2+ 1/(4)2 + 1/(in CI think I have been working on this problem too long. I still cannot get the codes to work. I changed the codes to:
Code:for (count =1; count <= terms; count++) { pi = (1.0 /(terms * terms)*2); } pi = sqrt * pi; pi= pi * 6;
Leave a comment:
-
pyramid replied to Help with apppproximate value of pi = sqrt(6* (1/(1)2 + 1/(2)2 + 1/(3)2+ 1/(4)2 + 1/(in CThe description of the problem is actually the same as what the instructor gave us ( i copied and pasted here). I am so frustrated because the program should be simple, but yet, I can't seem to generate the correct codes. Granted that I'm new to this class, I should at least understand the instructions.
I changed my codes from the original codes using (1)^2, (2)^2, (3)^2,...,n^2., . I tested using 100 as 'n' of terms, and...Leave a comment:
-
pyramid replied to Help with apppproximate value of pi = sqrt(6* (1/(1)2 + 1/(2)2 + 1/(3)2+ 1/(4)2 + 1/(in CThank you guys. I worked on this more last night, and finally gave up around 10 p.m. -
I'm really excited about the results you got when you made the change. I will change the codes using the guidelines you provided. I'll post here again once I get my change completed.
Thanks again.Leave a comment:
-
pyramid replied to Help with apppproximate value of pi = sqrt(6* (1/(1)2 + 1/(2)2 + 1/(3)2+ 1/(4)2 + 1/(in CI added the sqrt * pi, and the result is as you said, around 4...... I still cannot submit because it's not running the program completely (with correct results). I don't understand why it's not working.
I appreciate your input. Please let me know if you can think of anything else that may be causing the problem. I will continue to work on the codes. Thanks....Leave a comment:
-
pyramid replied to Help with apppproximate value of pi = sqrt(6* (1/(1)2 + 1/(2)2 + 1/(3)2+ 1/(4)2 + 1/(in CThanks.
Code:pi = pi + (1.0 / (2.0 * count));
I changed the code and removed the "-1". The result is 15.562132552918 9 (using 100 as terms). It is still incorrect, but it's closer to the correct answer. I worked on this all day yesterday and I just can't figure out why it's not working.
Also, I apologize that I didn't put the codes in block. I just learned that today.
...Leave a comment:
-
pyramid started a topic Help with apppproximate value of pi = sqrt(6* (1/(1)2 + 1/(2)2 + 1/(3)2+ 1/(4)2 + 1/(in CHelp with apppproximate value of pi = sqrt(6* (1/(1)2 + 1/(2)2 + 1/(3)2+ 1/(4)2 + 1/(
Hello
I am working on one of my lab for this week, which calculates the approximate value of pi. Listed below is the actual problem, which I am posting here, so that you can see the different requirements for the program.
The program is simple. I used the ‘for loop’ to define the number of increments, then set up a formula to calculate the pi. My codes compile with no problem, but the result is incorrect. One... -
A BIG THANK YOU to all of you.... My codes compiled in DEV, and it passed the automatic grading system in my class. You guys made my day (scratch that...) my entire week! Thank you.
/* This program will determine if the user inputs can represent the sides of a triangle. An IF/ELSE statement is used to determine if the user input is valid or not. */
#include <iostream>
using...Leave a comment:
-
Thanks again.
I apologize, but I'm a little lost.
I understand that it's better to change the data type to BOOL instead of INT. But I will still need to have a variable to return the result to (whether it's true or false).
bool isValid (int tri_a, int tri_b, int tri_c)
{
if ((tri_a + tri_b > tri_c) && (tri_a + tri_c > tri_b) && (tri_b + tri_c >...Leave a comment:
-
To call the isValid function to Main is my problem. What I learned in class (an hour’s worth) was nothing like I would use here, (or maybe I’m just trying to make something ‘simple’ so complicated).
To call isValid function to main:
isValid = ( the argument is what I am having problems with);
I didn’t think that I needed to declare a new function, but I didn’t how else to call the function...Leave a comment:
-
I tried the == instead of the assignment = but it still produced the same results. Thank you for catching that, I'm sure I need to use the equal == instead of the = assignment sign.
I have been working on this problem for 3 days now. We're only on our 9th day of class.
Thanks....Leave a comment:
-
The only difference I can see is that the when I called the function, the return type i used is VOID, and the other is INT.
Thank you....Leave a comment:
-
c++ isValid Function always returning a true value.
I am new to C++, and one of the homework we have pertains to Functions. The problem is:
Write a function called isValid that determines whether any 3 values can represent the sides of a triangle. The main function should prompt a user to enter 3 sides of a triangle, call isValid and output valid or invalid. The isValid function should have 3 parameters and return a bool. Given sides a, b, c; if a + b > c and a + c > b and...Last edited by sicarie; Oct 9 '07, 03:21 PM. Reason: You found the Indent and Bold tags, but not the code tags?
No activity results to display
Show More
Leave a comment: