C++ :: Function That Computes Result Of Formula For Two Sets Of Inputs
Nov 14, 2013
I'm currently writing a program and a portion of it needs to have a function that computes the result of a formula for two sets of inputs. It then has to calculate and display the difference between the two results.
I have code that takes the input from the user and converts it to the type that I need. In this case we are talking about latitudes and longitudes that will be converted to degrees, then to xyz coordinates.
View 1 Replies
ADVERTISEMENT
Aug 28, 2013
I just want to practice in the language so i wrote this simple function that computes the factorial result of a certain number. The problem is that for all numbers > 20, the results are wrong ( < 20 all good).
I already learned that normal "long" type in c is more like 32 bit int and not 64 bit like a long type in java. so I used here a "long long" type.
why am I getting strange results above the number 20? isn't 64 bit enough to hold those numbers?
Code:
long long factorial(int n);
int main() {
long long result = factorial(20);
printf("%lld",result);
[code] ...
for 21 i get: -4249290049419214848
where the right result shoud be: 51,090,942,171,709,440,000
View 8 Replies
View Related
Mar 21, 2014
Write a function that computes and returns the score for a permutation, i.e. the number of reversals required to make arr[0] == 1.
HAVE TO USE FOLLOWING FORMAT:
Code:
// POST: Returns the number of reversals needed to make arr[0] == 1
// if the reversal game were played on arr
// Note: If arr[0] == 1 initially, then score(arr, n) returns 0 AND this is what i could muster;
[code]....
View 2 Replies
View Related
Oct 18, 2014
How can I declare a set of strings that i want to be ordered by a boolean function Comp? Like the one you would write in
sort(v.begin(), v.end(), comp);
I tried
set<string, Comp> S;
but it doesn't work
And the same question for priority queues, can you specify the function you want your elements to be sorted by?
View 4 Replies
View Related
Nov 5, 2013
Night now I'm working on part of a function that scans in two sets of coordinates. Is there a way I can scan both sets of coordinates in with the same scanf?
ex. scanf("%d%d%d%d," &destroyer_1, &destroyer_2, &destroyer_3, &destroyer_4)
but that didn't work...
Code:
printf("What are the first coordinates for destroyer:
");
scanf_s("%d%d", &destroyer_1, &destroyer_2);
gameboard[destroyer_1][destroyer_2] = 'd';
printf("What are the second coordinates for destroyer:
[Code] .....
View 5 Replies
View Related
Sep 3, 2013
Its a basic math function using the exponential growth formula which is correct but the computer is not outputting the right numbers.
Code:
#include <stdio.h>
#include <math.h>
int main() {
int blanketsquares, num1, num2, blanket,remainder;
[Code] .....
View 6 Replies
View Related
Mar 28, 2013
I have this simple code here:
Code:
#include <iostream>
int multiply (double x, double y) {
double result = x*y;
return (result);
[Code] ....
I get the answer 5.94 (which is what I'm looking for). I can't work out why the first example is not outputting a decimal number. I have set the variables as a double so I just can't see why this is not working for me.
View 1 Replies
View Related
Aug 2, 2014
#include <iostream>
#include <iomanip>
#include <fstream>
[Code]....
i have already tried putting system pause or cin.get after it, but no luck
View 1 Replies
View Related
Mar 2, 2014
c++.....in my program i have 3 string-s (string houses,string ink,string buildings)and i must add function substr()... In the program i need to add a function that receives a parameter of type string. The task function is that the resulting string is inserted characters '=' to split a string of characters into subsets 5 letters long. If you come to the end and no more letters after the equal sign is not added. The function should not display anything but the resulting string is returned as a result. Example:
A function recive: "housesinkbuildings" .The function returns: "house=sinkb=uildi=ngs" in The main program Add call of this function so that it is specified as a parameter string consists houses,ik, buildings.
View 2 Replies
View Related
Oct 24, 2014
write a program that computes the factorial of a number and displays it. A factorial of a number (written N!) is defined as N * (N-1) * (N-2) * (N-3) ... *1 In other words, 5! = 5 * 4 * 3 * 2 * 1 = 120 and 3! = 3 * 2 * 1 + 6.
Example of output 15 is 1.30767e+012
Can't get it to display error when user enters a number lower than 2 or higher 60.
// Program to calculate factorial of a number
#include <iostream>
#include <iomanip>
[Code].....
View 13 Replies
View Related
Sep 30, 2014
I am trying to do a simple for loop that computes sum of a certain number of integers and then outputs the sum.
.text
.globlmain
main:
li $9, 0
li $10, 0
li $11, 10
li $12, 0
li $13, 0
[Code] ....
There error I keep getting is on the line with the branch
Instruction references undefined symbol at 0x0040003c [0x0040003c] 0x10200000 beq $1, $0, 0 [exit-0x00400038]
View 1 Replies
View Related
Feb 16, 2015
Write a program that reads alphanumeric characters from the keyboard, and computes the average ascii value of the alpha numeric characters, the average alphabetical character, the average numeric character and the average uppercase character. Outputting each, you program should terminate reading once it read a non-alphanumeric character.
Here's what i have so far.
Code:
#include <stdio.h>
#include <ctype.h>
int main(void) {
int value = 'a';
int digit_loop = 0;
int alpha_loop = 0;
int upper_loop = 0;
[Code] ....
View 7 Replies
View Related
Apr 18, 2014
I have a vector of sets in which I wish to remove a set from the vector, if it contains a certain value, is there any way of doing this?
for(int j = 0; j <= clauseVector.size(); ++j){
if(clauseVector[j].find(find) != clauseVector[j].end())
std::cout << "FOUND: " << propagator << "
";
}
}
This is what I have been using to find the element, but is there a way to remove the set that contains the element?
If needed I can include the full code
View 11 Replies
View Related
Apr 24, 2013
Ok so I am currently trying to add and subtract two sets of integer arrays. When I run my program, the program does not subtract the numbers from the first set with the numbers from the second set. Could anyone here take a look at my code and help me figure out what the problem is?
#include <iostream>
#include "SafeArray.h"
using namespace std;
[Code].....
View 1 Replies
View Related
Jan 5, 2014
I have two std::sets S1 and S2 which I need to merge.
I know that the largest element of S1 is less than the smallest element of S2.
the additional information about S1 and S2 should enable me to do the insertion of each element in costant time instead of log(N).
what is the fastest way to calculate the union of the two sets?
View 6 Replies
View Related
Apr 18, 2014
I have a vector of sets, which I am removing any element which contains a certain value. For example, if I was looking for 2:
[0] 1 2 3
[1] 4 5 6
After the program was run, I would be left with just [0]4 5 6.
This is the code I have been using
auto iter = std::remove_if( clauseVector.begin(), clauseVector.end(),[propagator] ( const std::set<int>& i ){
return i.find(propagator) != i.end() ; } ) ;
clauseVector.erase( iter, clauseVector.end() ) ;
I want to know, is there any way I can tweak this code so that it only removes one part of the set rather than the whole thing. For example with above example, I would be left with
[0] 1 3
[1] 4 5 6
View 4 Replies
View Related
May 30, 2013
So I'm attempting to write a program that will parse through a large file (genome sequences) and I'm basically wondering what options I should consider if I wanted to either:
a) store the entire genome in memory and then parse through it
b) parse through a file in small portions
If I go with "a", should I just read a file into a vector and then parse through it? And if I go with "b" would I just use an input/output stream?
View 5 Replies
View Related
Jul 3, 2012
I've recently started to learn C++ and I'm using codeblocks as my IDE, but I keep getting problems with AVG free edition picking up random pieces of code as Trojans ?! I've put an example of some code that sets it off below, and the error message I get. Is there anyway I can set AVG not to trigger with any codeblocks coding I've done? I guess I could tell AVG not to trigger for that folder, if that's even possible?
Code:
#include <iostream>
using namespace std;
class MyClass{
public:
void coolSaying(){
cout << "BUST A MOVE!!" << endl;
[Code] ....
Error I get:
File name: h:DesktopC++ projectsclasses and objects 1 inDebugclasses and projects 1.exe
Threat name: Trojan horse Agent3.BMSZ
Detected on open.
View 14 Replies
View Related
Feb 17, 2014
The program is to find intersection,union and difference of two sets. The program take the input correctly but after it crashes with the message that some exe is not working...
Code:
#include<iostream>
using namespace std;
void Input(int *A, int*B, int size1, int size2)
//input function {
[Code] ....
View 3 Replies
View Related
Nov 17, 2014
I have come across a problem lately. You are given a set of n sets with m variables.. for instance {a,b,c,d}, {b,c,d}, {b,c}, {c,e,f}, {e,f}. And you want to eliminate elements from these sets with the restriction that you can only eliminate one item from each set and each item can only be eliminated from one set (i.e. if you've eliminated b from set {a,b,c,d}, then you cannot eliminate it from {b,c,d}). The problem is writing an algorithm which determines the maximum number of elements you can eliminate. And I'm hopelessly stuck... of course, you could backtrack it and determine this number but I feel it could be done more efficiently..
View 2 Replies
View Related
Jun 21, 2013
Equation for compound interest. The interest is supposed to be $43.34 according to the book, I am ending up with around $35. The actual equation is amount = principal * (1 + rate/t)^t where t = number of times compounded per year. I still have to go through and clean up all the code I just want the formula working first.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main () {
float princ, rate, comp, savings, interest, rates, year;
[Code] .....
View 2 Replies
View Related
Jan 28, 2014
We are suppose to build a program to do the quadratic formula, which isnt really a issue. my issue is i have a if else loop and my if is being ignored.
what i want it to do is is state that if the (b * /> - 4(a)© is a negative, then it prints out stating it cant do this.
note: i know that i can use the i number system but we have been asked to not too and to do this instead.
here is my code
#include <stdio.h>
#include <math.h>
int main() {
float a, b, c, d, e, f, g, h, i; /* i would love to figure out a way to do this without so many variables*/
[code]....
View 3 Replies
View Related
Sep 24, 2014
Im having problems coding this
A = P(1 + r/n)nt
//Declared test cases
float principal = 200000.00, annualInt = 0.03;
float years = 10.0;
float calcInterest1(float principal, float years, float annualInt) {
float interest1;
float nt = annualInt*12;
float A = principal+annualInt;//Accrued Amount
interest1 = (A = (principal*(1+years/100))pow(nt));// A = P(1 + r/n)nt
return interest1;
}
View 1 Replies
View Related
Mar 21, 2014
I am trying to create a code and cannot get the following part to work :
for (int n = 0; n = timesteps; n++)
{
n = n + 0.1 ;
cout<< "timesteps"<< n << endl ; //print time step value =0.1
for (int j = 0; j < nodesinx; j++)
{
T[j][n+1] = T[j][n] + 0.16 * (T[j][n] - 1[n] - 2[T[j][n] + T[j] + 1[n] ; //equation
n= n + 0.1 ;
cout<< "temperature" << T[j][n+1] << endl;
T[j][n+1] = 0.0 ;
}
}
View 1 Replies
View Related
Jul 27, 2014
It is possible to define the formula of prime numbers in C++ language?
View 1 Replies
View Related
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