determining if a value entered in loop is an odd or even number. Also, the value can't be int because it may be a decimal value(therefore i cant use the if(x%==0).
I need to replace the if(value%2 ==0) else num_even++ statement in my code with something else that will work with float to determine odd vs even.
#include <iostream>
using namespace std;
int main() {
int num_values;
float sum_values = 0;
int num_neg_values = 0;
int num_pos_values = 0;
I need function to determine where to place new element in sorted array. I want to use binary search to find index where element should be placed, when push all others.
Prototype should be something like
int WhereToPlaceElement(ElementType hash); // uses private atribute ElType** elements
I have tried my best to write, but all tries ended in inf loops and reading invalid locations of array.
I am trying to extract the numbers from Numbers.txt, and then put them in the correct file, either Odd.txt or Even.txt, depending on what they are. And I have gotten to a point where I am not sure what to do; right now it just reads Numbers.txt and then the program ends.
char A[]={}; this is the array in c++ of unknown size, now I want to enter some alphabets via loop and want to be the no. of elements i entered the size of the array. .
I am new at c++ and I am trying to write a code to determine the maximum deflection at the end of a cantilevered beam. I am given the formula : deflection= (4 W L^3)/(E B H^3) where W is the load weight, L is the beams length, E is the modulus of elasticity, B is the beams base, and H is the beams height.
i have to read a file with between 5 and 10 pairs of numbers, each on a different line. i can read the file, and wrote something to save the length of the file as a variable, but when i use it i start returning crazy data. the problem is in the do while loop and i want to change the i< in the for loop to "lines" so the code stops when the last digit is read. if i use i<10 the file has extra digits is the file is only 8 or 5 pairs of numbers.
FILE *Fpointout; FILE *Fpointin = fopen ("test.txt","r"); //read this one Fpointout = fopen ("out.txt","w"); //write this one if (Fpointin == NULL) //if no file in source { printf ("File does not exist."); //tell user it is not there
I have to make a program to read a file with strings and determine if they are palindromes. The problem is that the program says that they're all palindromes.
int main() { ifstream inFile; ofstream outFile; inFile.open("in.data"); outFile.open("out.data"); if (!inFile || !outFile) //to display error if input files are invalid
I am trying to write a function that determine if a file in a directory is of a gif/bmp/png/jpg extension. Right now I think I have correctly written my code all the way up to listing the files in the directory and opening them in binary mode.
Now, I am struggling with figuring out how to determine what extension the image is. Right now i am just focusing on writing my "bool isGif();" function... To determine if a file is a .gif extension using binary, the first 6 bytes of the file will contain either GIF87a or GIF89a.So, to do this I would read the first six bytes of the file using the function below, correct?
fin.read((char *) &a_file, 6)
Then, once I read in the first six bytes how would I conditionally compare it to determine if it is a .gif? Would I just use
if(fin == "GIF87a II GIF89a) { \do something here }
N=1st number M=2nd number(accrding to my prof we will name it N and M ctr= increment of factorial of N, ctr2= increment of factorial of (N-M)
the problem is when i got the factorial of N / factorial of (N-M) i need to get the last non zero digit. so i use mod if it has zero in it. but mod can be only used with an int value. and when i change it to int value, the value of fact1 which is a float change
I am looking for a math/big num library, that allows me to convert 32/64/80 bot float numbers to string and vice versa.
Precision & accuracy is of importance here, and since this is an IEEE standard, i have high hopes that there are libraries for this out there, which would save me the hassle of trying to implement this myself...
I am working from my "ansi c" book by steven lawlor, page 73 program 2. write a program that accepts two numbers from the keyboard and prints the following information.
variables first second execution First number ? 7 Second number ? 2 the second goes into the first 3 times with a remainder of 1. the quotient is 3.5.
Code: #include <stdio.h> main() { int first, second; scanf(" %1i %1i", &first, &second); printf("First number ? %1i
[Code] ....
//I included this as I had some error message come up // before, not sure if this is correct though? } it shows what is expected but I cant get the 3.5.
I have tried %f and variations of width/precision but still not luck. Also, when I click on the application and put in the variables I press enter, the program executes and disappears so I cant see the result. how do I get the program to stay up until I want to get rid of it?
I just checking but confused with float. in that code same size int, and same type double are working but float showing nothing in printf..why?? i'm using GCC compiler int 32bit win7 os
I am entering numbers to float ... I want program to find out, which first number is not from specific interval. How to do it ? Example: Enter input : 5 10 20 30 50 46 . 30 is invalid. Here is the code :
Code:
while(scanf("%f",&input)!=EOF || input==0) { sum=input+sum; if (getchar() == '
why does the 2 variables, loanAmt and intRatem not work when they are multiplied together. The question is " Write a program that calculates the remaining balance on a loan after the first, second and third monthly payments. "
In w32 my program has been running ok, but when run in a w64, it crash at the printf. If I change the definition of the function to return double it runs ok. in printf format string - Wikipedia, the free encyclopedia , in the "type" section I see there is no definition to print a float, but %f is for double in fixed point.So the question is what is the correct way to printf a float? must I cast? or is it better to return double? if so, does it have a performance penalty?
Unless I'm missing something, it's now possible(ish)? A little concept is below, very rough around the edges. Still though, if this is valid by standard C++, why can't we have built-in support for float / double template parameters?