C :: Calculates Area Of A Triangle - If Statement

Jun 10, 2013

I am currently learning "if statements" while doing a program that calculates the area of a triangle. My problem is that the result is always "0". I am pretty sure the problem lies within my math, but how I have set it up wrong.

I am using Heron's Formula. Here it is for reference:

area=sqrt(s(s-a)(s-b)(s-c)) where s=(a+b+c)/2

Code:
#include <stdio.h>
#include <math.h>
int main () {

float area, sideA, sideB, sideC, halfP;

[Code] ....

View 4 Replies


ADVERTISEMENT

C :: Program That Calculates The Area And Circumference Of A Circle

Sep 27, 2014

I trying to write a program that calculates the area and circumference of a circle.

This is what I wrote so far.

Code:

#include <stdio.h>
void main()
{
int r;
int pi=3.14159265;
float cir,area;
printf("
enter the radius of the circle ");

[Code]...

the Problem is when I input the radius the answer I get is zero regardless of the the radius. Am I missing something?

View 4 Replies View Related

C++ :: Program To Calculates Hypotenuse Of A Right Triangle

May 12, 2014

How to do the function part here is the question. "Write a program that calculates the hypotenuse of a right triangle. the program should ask the users to enter the length of the two legs of the right triangle and the program should call a function hypotenuse() that will calculate and display the length of of the hypotenuse. NOTE: The program should include a prototype for the function hypotenuse()" i have this so far

#include <iostream>
4 #include <cmath> // Needed to use the sqrt function
5 using namespace std;
6
7 int main()
8 {
9 double a, b, c;

[Code] ....

View 4 Replies View Related

C/C++ :: Area Of Triangle Calculator?

Nov 16, 2014

I was asked to build a small program to calculate the are of a Triangle but my code must have some problem.. />

#include "stdafx.h"
void main()
{
int a,b;

[Code]....

I get this errors:

-warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.

-warning C4244: '=' : conversion from 'int' to 'float', possible loss of data

View 4 Replies View Related

C++ :: Program To Find Area Of Triangle?

May 26, 2013

i have written a program to find area of triangle, but i meet some errors,

//******area of triangle******//
#include<iostream>
using namespace std;

[Code].....

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++ :: Compute Area Of A Triangle Using Cross Product

Jan 8, 2015

I have to write some cpp program which computes area of a triangle using cross product,we give 3 vertices as R2 and 3 edges as double.

I am beginning like this;

#include <iostream>
#include "R2.h"
#include <cmath>
using namespace std;
double area ( R2 *A,double *z)

[Code] .....

View 5 Replies View Related

C/C++ :: Find Triangle In Array Of N Triangles Which Has Largest Area

Apr 6, 2015

How to find triangle in an array of n triangles which has the largest area?

#include <stdio.h>
#include <stdlib.h>
#include<math.h>
typedef struct {
double x,y;

[Code] .....

View 14 Replies View Related

C :: Program That Calculates Batting Average

Apr 21, 2014

I'm trying to put what i've learned into a little program that calculates batting average.

I want to store the batting averages of the players in an array and printf the best average at the end by name for example Dennis Ritchie had best batting average at .600.

I'm having trouble understanding how and what type of array to use.

Code:
int main(int argc, const char * argv[]) {
char playerName[20];
int totalPlayers, atBats, totalHits, x;
float battingAvg;

// Get total number of batters
printf("How many batters?

[Code] ....

View 2 Replies View Related

C :: Calculates Factorials Of User Input

Apr 12, 2013

This is a function that calculates factorials of the user input.I'm not getting a favorable printf result.

Code:

void calcFactorial ()
{
int arr [100];
int num = 0;
int i;
int factorials = 0;
int product = 1;
}

[code].....

View 2 Replies View Related

C++ :: Create Function That Calculates Sum Between Two Containers

Jul 1, 2012

I need to create function Sum() that calculates sum between two containers. Code below work fine except function Sum between two containers...

How I should re - write my code that everything work fine.

Condition of exercise is : "Also create a Sum() function that calculates the sum between two iterators. The function then uses the template argument for the iterator type and accepts two iterators, the start- and end iterator"

1>------ Build started: Project: HP2_ex2_iter, Configuration: Debug Win32 ------
1> main.cpp
1>c:all myс++ha level 7solutionlevel 7 homework overview of the standard template libraryhp2_ex2_itermain.cpp(47): error C2275: 'C1' : illegal use of this type as an expression

[Code]...

View 5 Replies View Related

C++ :: Function That Calculates Euclidean Distance Between Two Points

Feb 24, 2015

I am trying to write a function that calculates the Euclidean distance between two points described by
𝑑𝑖𝑠𝑡𝑎𝑛𝑐𝑒 = √(𝑥1 − 𝑥2)2 + (𝑦1 − 𝑦2)2
Input Prompt
Enter x1, y1, and x2, y2:
Output Prompt
The distance is XXXX.XXX

Replace XXXX.XXX with the calculated distance precise to three decimal points.

Will this be a smilier input to the same forum that wasted posted a few years ago on this site?

Here is the link... [URL]..

View 2 Replies View Related

C++ :: Create A Program That Calculates Fraction Of Time?

Dec 16, 2013

I am trying to create a program that calculates fraction of time remaining when a student leaves during the middle of the semester. I have to use function files here. I am having trouble with the division in function long double tuitionfrac(int, int, int). No matter what numbers are entered, fractime gives an output of 0. I don't understand that.

long double tuitionfrac(int opening, int leaving, int semend)
{
int lefttime = semend - leaving;
cout << "Left time " << lefttime << endl; //for error checking
int tottime = semend - opening + 1;
cout << "Total time " << tottime << endl;
long double fractime = lefttime/tottime;
cout << "fractional time " << fractime << endl; //always returns as 0.
return fractime;
}

View 4 Replies View Related

C++ :: Finding Program That Calculates Student Grades?

Jun 7, 2013

I have to make a program that reads two student grades, the average of the two has to be 6, if you can not take an average of 6, will make a third test and calculate a new average.

I'm not getting the new display medium, without repeating the approved and disapproved?

// TRABAV2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[]) {

[code]....

View 1 Replies View Related

C/C++ :: Using Program That Calculates Test Average Using While Loop?

Sep 23, 2014

I am working on a program that calculates the average of a list of test scores entered, with the list ended with a negative score (which is not calculated), as long as a user enters a name.

#include<iostream>
#include<string>
using namespace std;
int main() {
string name;
double score = 0.0; //user input score

[code]....

I have gotten the while loop to function. The problem lies in the calculation in the average of the test scores, such as when I enter the scores 87 76 90 -1 , which is supposed to give an average of 84.3 but my result when outputted is 86. what the problem is and what I can do to fix this error?

View 1 Replies View Related

C++ :: Switch Case - Program That Calculates Students Grade

Apr 18, 2013

Trying to write a program that calculates a students grade based on how many assignments have been graded. I am using a switch case since there is a total of 5 assignments, however when I enter case 1, and enter in how many I got out of 100, it just closes the program it doesn't go to the next part.

#include <iostream>
using namespace std;
char calculategrade(int total);
int main() {
// local variable declaration:
char input;

[Code]....

View 6 Replies View Related

C++ :: Define A New Member Method Which Calculates Value Of Term And Display It

Jul 30, 2012

A class called 'sample' with the data a, b and c and two methods as defined below. Define a new member method 'term()' which calculates the value of the term (2b - 4ac) and displays it.

Define the method outside of the class definition. Write the main method to create an array of 2 objects called D of class 'sample' and display the values and find the solution to the term (2b - 4ac)

My code so far:

#include <iostream>
using namespace std;
int term(int a, int b, int c) {
int result;
result = (2*b - 4*a*c);

[Code] ....

Problem: I keep getting error messages, here is a look at the ones i'm getting.

error: ISO C++ forbids declaration of 'cout' with no type.
error: expected ';' before '<<' token.
error: new types may not be defined in a return type
error: expected unqualified-id before '{' token.

View 5 Replies View Related

C++ :: User Input Number And Then Computer Calculates It For Fibonacci Series

Mar 15, 2013

I was asked to write a code that has the user input a number and then the computer calculates it for the Fibonacci series. The output should be separated by commas and a period should follow the last number. Ex. 1,2,3,4,5. <---period

I can't seem to get the period at the end. I have the commas and everything else. Here is my code:

#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
double num;

cout << "How many Fibonacci numbers do you want to display?";

[Code] ....

View 3 Replies View Related

Visual C++ :: Program That Reads Numbers From A File And Calculates Average

Mar 13, 2014

[URL] .....

Here is my code and basically these are the steps. I feel like we have something good to work on but we keep getting errors.

a. Data to the program is input from a file of an unspecified length; that is, the program does not know in advance how many numbers are in the file.

b. Save the output of the program in a file.

c. Modify the function getNumber so that it reads a number from the input file (opened in the function main), outputs the number to the output file (opened in the function main), and sends
the number read to the function main. Print only 10 numbers per line.

d. Have the program find the sum and average of the numbers.

e. Modify the function printResult so that it outputs the final results to the output file (opened in the function main). Other than outputting the appropriate counts, this new definition of the function printResult should also output the sum and average of the numbers.

View 12 Replies View Related

C++ :: Transfer If-else Statement Into Switch Statement?

Sep 7, 2013

How to make if else code below into SWITCH STATEMENT?

cout << "Enter the temperature: ";
cin >> temp;
cout << "Enter the pressure: ";
cin >> pressure;
cout <<endl;

[Code]....

View 6 Replies View Related

C++ :: Calculate Area Of Circle Without Pi

Mar 22, 2013

I was given an assignment for class to calculate the area of a circle using only the radius as a user input and not using Pi in the code. I need to do this by calculating the areas of a series of rectangles under the curve and adding them together. Using nested loops to continuously reduce the size of these rectangles until the approximated area value is within a margin of error less than 0.1%.

Code:
#include<iostream>
#include<cmath>
using namespace std;
int main ()

[Code] .....

View 7 Replies View Related

C++ :: Calculating Area And Perimeter

Sep 28, 2014

I am having trouble with my C++ program. My program asks the user to enter any number greater than 0 and less than 20, and if the user enters any number(s) outside the acceptable range, the output should display:

input outside of exceptable range > 0 and < 20
length: 1 width: 1 area: 1 perimeter: 1

But in my program, this output displays no matter what the user types (even if the numbers are in the acceptable range, when it should be displaying the length and width the user enters and also displaying the calculated perimeter and area whenever the user enters number(s) in the acceptable range. Here is my code:

#include <iostream>
using namespace std;

float class_rectangle_area();
float class_rectangle_perimeter();
float class_rectangle_length();
float class_rectangle_width();

[Code] .....

View 4 Replies View Related

C/C++ :: Program That Uses The Radius To Get Area?

Apr 28, 2012

How can i come up with a program that uses entered radius of a circle to find its area

View 1 Replies View Related

C++ :: Area And Volume Of Cylinder?

Apr 27, 2013

I would like to calculate area and volume of cylinder but radious and height should be integer, float and double.

View 14 Replies View Related

C :: Enter Test Marks Of Several Students And Calculates Average Marks Of Each Student

Mar 10, 2013

Write a program that a prof can use to enter the test marks of several students and which calculates the average mark of each student. Ask the user how many students he has, then ask him to enter each student's marks. When 999 is entered, calculate the average mark for that student (not counting the 999) and print the average. Then go on to the next students until the marks for all students have been entered, calculated and the average printed.

Code:
#include<stdio.h>
main() {
float student,mark,total=0;
float a,b,c;
int num = 999;
printf("

[Code] .....

View 2 Replies View Related

C++ :: Calculate Area And Volume Of Cylinder?

Apr 27, 2013

I would like to calculate area and volume of cylinder but radious and height should be integer, float and double. How can i do?

View 9 Replies View Related







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