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;
}
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
I'm having a problem when i convert from fraction to string. When I run my program it runs fine I'm supposed to get an output of the fraction ex (2/5) and the decimal 0.4 the problem is that it does not output the fraction all I get it / and 0.4
the code for converting from fraction to string is the following std::string string; char numerator[100]/* = {0}*/; char denominator[100]/* = {0}*/; _itoa_s(numerator_, numerator, 10); _itoa_s(denominator_, denominator, 10);
I'm trying to create a program to calculate the flight time and fuel burn of an airplane. However when I repeated the whole calculation, it did not show any data or result like the previous calculation. In addition, the "If" statement that I used to test the "fuelRemain" doesn't work properly. I can't figure out why.
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?
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;
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[]) {
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?
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;
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.
I am trying to create two classes: a Date class and a Time class. The Date class has to have three private data members: day, month and year. The Time class should have two private data members:hour and minute. Each class should have two member functions: a constructor and display. I am lost and my code won't run ....
class Date { private: int month, day, year; public: Date(int m, int d, int y){ month = m; day = d; year = y;
I need to create a function that performs the addition of x days at a time, taking two integer values, the first being a date (yyyymmdd format) and a number of days to add / subtract that date.
How can I perform validation if the entire amount received is a valid date and how can I add x days of that date?
i am having issues converting a fraction to a decimal, i think the code would go in the istream because it is working with input data but i just cant figure it out.
#include <cstdio> #include <string> #include <iostream> using namespace std;
I'm writing a function that compares two fraction. if the fractions are equal it returns 0. If the fraction in the first parameter is less than the fraction in the second parameter it returns a negative number. Otherwise it returns a positive number. in doing so convert the fraction to a floating point number.
completing the function to run
typedef struct fracion { int numo; int denom; }fraction;
I am trying to write a Fraction class and getting the following warning when compiling my code :
Fraction.cpp: In constructor 'Fraction::Fraction(double)': Fraction.cpp:8: warning :converting to 'int' from 'double'
My Fraction.cpp class looks like :
#include "Fraction.h" Fraction::Fraction(int n, int d):num(n),den(d) { cout << This is double param constructor <<endl; } Fraction::Fraction(double d):num(d),den(0)
I'm writing a function that compares two fraction. if the fractions are equal it returns 0. If the fraction in the first parameter is less than the fraction in the second parameter it returns a negative number. Otherwise it returns a positive number. in doing so convert the fraction to a floating point number.
typedef struct fracion { int numo; int denom; }fraction; int compareFractions (fracion, fraction);
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 () {
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?