C :: Rounding Function Not Working
Oct 12, 2013
Why the roundf function is not successfully rounding my numbers.
Code:
#include <stdio.h>
#include <math.h>
//function declarations
void CelToFah (int ctemp, int ftemp);
[Code]....
it produces a correct number when called, but it is not a rounded number, the roundf((float)cel) does nothing. I get the same number with and without it.
View 6 Replies
ADVERTISEMENT
Jan 16, 2014
I want to round to the 2nd digit in a float. Such as 1.85458 to 1.85. How would i go about doing this. I currently keep rounding to the closest integer so the above would round to 2.
Code:
#include <stdio.h>
#include <math.h>
int main(void){
float n;
[Code] ....
View 4 Replies
View Related
Feb 4, 2014
I'm having trouble with rounding to the nearest cent in this program. It's the only thing that i need. The result i need is just off by one cent. I tried multiplying the interest amount by 100 and adding .5 then dividing all that by 100 but that just made it worse. Here's the code:
Code:
#include <stdio.h>
int main()
{
int count=0;
[Code]....
View 6 Replies
View Related
Apr 23, 2013
I have an assignment for uni which requires the program to ask the user to input a number in for a variable to use in later equations. The assignment specifies that if the number that is input into the program is not an interger that it needs to be rounded UP to the nearest interger. e.g. 2.5 = 3, 5.00001 = 6 etc. i have identified this variable using "int" which i know makes it an interger however it also always rounds the number DOWN to the nearest interger. I was just wondering what the best way to approach this problem was. The only idea i have is to put + 0.99999 at the end of this variable when it is worked out so that if it is not a whole number it will be raised above the next interger and then rounded down however this will not work if there is too many decimal places.
View 6 Replies
View Related
Mar 9, 2014
How do I round to the nearest half integer?
Example;
0 to 0.2 = 0
0.3 to 0.5 = 0.5
0.6-0.9 = 1
What's the formula for C++?
I found a way to do it in math but I want to know what I'd have to put in C++. It's (x*2+.5)remove decimal numbers and divide by 2. What do I put in place of "remove decimal"?
For ex; x = 8.4 using (x*2+.5)remove decimal then divide by 2.
8.4 * 2 = 16.8
16.8 + .5 = 17.3
17.3 - decimal = 17
17/2 = 8.5
I want to do something like;
cout << " Half number: << (x*2+.5)remove decimal/2 << endl;
What would I have to put in place of "remove decimal"?
View 4 Replies
View Related
Oct 4, 2014
Ok so I'm in a programming 1 class working with c++. I have the following assignment:
Write a C++ program that:
asks for and accepts the Percentage earned with as a double (i.e. 75.45)
rounds it to an integer (>= .5 rounds up, <.5 rounds down.)
prints the original Percentage and the corresponding Grade and Points exactly as shown below.
prints an error message for any input that is less than 0 or greater than 100.
For example, if user enters 89.4, the program prints out:
Percentage: 89.4% Grade: B Points: 3.00
You must use an if-else statement to do this in your program.
Use fixed and precision output manipulators (see Ch. 3) to display the values with the exact precision shown above.
IMPORTANT:
Each if statement condition should contain only one comparison! read this again
This means code that is similar to this is NOT okay: if (Percentage >= 80.00 && Percentage <90.00)
This code is not acceptable because the if statement condition above has two comparisons.
(Hint: If you order your if-else chain statements correctly, you will only need one comparison in each.)
I have the program working, but I'm pretty sure I'm not rounding how my professor would like it to. This is my code:
#include <iostream>
#include <cmath>
#include <iomanip>
[Code].....
So my issue here is the rounding, and then theres the converting the double percetnage to an integer. In my next assignment I have to write the program with a switch statement.
View 3 Replies
View Related
Jul 18, 2013
I have made a random number generator to create a number between 1000 and 9000, but I always get numbers with many 10s and units. I want to round them 100s.
Is there any way to do this?
View 4 Replies
View Related
Jul 28, 2012
Rounding a numerical figure up to the nearest hundred. E.G.:
256 >> 300
654 >> 700
15 >> 100
I would like to know the formula to enter into Visual Basic 2008. I'm making a calculator Program, and i need a function that rounds up to the nearest 100...
View 5 Replies
View Related
Oct 28, 2013
I made this dice simulator which basically throws the dice 1 million times and outputs the frequency and percentage average for each side (1 to 6).
Everything is working fine, except my averages (floats) seem to be rounding up, causing 4% being "unassigned" at the end of the million rolls. I'm outputting with a setprecision of 2, but I only get 0's and no fractional numbers.
View 5 Replies
View Related
Jul 23, 2013
How would I be able to round a number in multiples of another...
Let's say width is 150
And multiple to be 64...
I want 150 to become 128...
if it was 160 to become 192...
The width number will change and I want to covert it in multiples of the other number example 64... The minimum value will always be the multiple number used...
View 7 Replies
View Related
Nov 27, 2013
Code:
#include <stdio.h>
int main() {
int m,c;
for(c=0;c<100;c++) {
m = c % 10;
printf("%d ",m);
}
return(0);
}
When I run this code in my compiler, I get the first nine or ten numbers, and then after that it just spells out the letters in my name in different sequences over and over.
View 3 Replies
View Related
Feb 20, 2013
I have two functions bool check_key(string cKey, string eKey) and bool check_digit(char digit1, char digit2), and I have declared both of them globally (is this the right terminology?) right after the "using namespace std;" and right before the "int main(){".
In the first one, I called the second one . But it is giving me the error: "no match for call to `(std::string) (int&)' ".
Code:
bool check_key(string cKey, string eKey) {
if(cKey!="" && eKey=="") return false;
if(cKey=="" && eKey=="") return true;
if(cKey=="" && eKey!="") return true;
if(cKey.length()!= eKey.length()) return false;
bool flag=true;
[Code] ....
View 2 Replies
View Related
Nov 9, 2013
the functions checks if the word is a palindrome like"level" "madam" etc. but with input "dfdfdfdffdfd" my recursive function fails.
Code:
/* main.c - Created on: Nov 9, 2013 - Author: Kaj P. Madsen*/
#define MAX 100
#include <string.h>
#include <stdio.h>
int checkPalindrome(char checkString[MAX]);
int checkRecPalindrome(char checkString[MAX], int strLgt, int a);
}
[code]....
results from "dfdfdfdffdfd" added some print to see that its the variables a and strLgt not functioning properly
Code:
dfdfdfdffdfd.
The word is not a palindrome(iterative)
strLgt: 11 a: 0
a: d strLgt: dstrLgt: 10 a: 1
a: f strLgt: fstrLgt: 9 a: 2
a: d strLgt: dstrLgt: 8 a: 3
a: f strLgt: fstrLgt: 7 a: 4
The word is palindrome (recursive)
View 4 Replies
View Related
Dec 6, 2014
The function Reverse does seem to work. Its supposed to take the words in a sentence and then reverse them. For example: "This is nice" to "Nice is this." When I type "This is nice" I get " niceniceis nice"
#include <iostream>
#include <string>
using namespace std;
[Code]....
View 1 Replies
View Related
Jan 24, 2014
Below is my .h file and the code below that is my function that I'm having troubles with. Its suppose to take in a users topic and see if that topic exists, if it does exist then find the keyword, commentcompare will find where that keyword is and delete the comment. However its not deleting anything and its returning temp is NULL.
class comment //adds a comment
{
public:
comment(char * create_comment);
[Code]...
View 3 Replies
View Related
Oct 15, 2013
i think my function call is not working and i dont know how to fix it. Basically i want it to output my getstudent function and once i get the information i want it to output with the displaystudent.
#include <iostream>
#include <string>
using namespace std;
void displayStudent(Student x) {
cout << x.first << ' ' << x.last << endl;
cout << x.id << endl;
[code]....
View 6 Replies
View Related
Oct 9, 2014
making my delete function work. My program does compile but my delete function doesn't work. I haven't finished my last two functions because I am focusing on the delete but how to Sell a title and print the value of all sold titles would be nice as well.
#include <iostream>
#include <cstdlib>
#include <string>
[Code].....
View 2 Replies
View Related
Apr 23, 2014
I am writing a program where f is the frequency and the x has the values as well. Now I am calculating the mean which is summation fx divided by summation f. I have the two functions working correctly but the getmean function is not working. It suppose to divide fx/f . check the code below
#include <iostream>
using namespace std;
const int SIZE=5;
class statisticalOperator{
[Code]....
View 2 Replies
View Related
Sep 6, 2013
I have a function that concatenate the strings in an array(2D)
Ex 1: Sean Connery Micheal King James Wood
Result: SeanConnery MichealKing JamesWood ...
The concatenation function working correctly and displays correctly in the function. But if I make another function to display it, it shows this
Ex 2: SeanConnery Sean MichealKing Micheal JamesWood James..
It adds to first name. Why?
Code:
void Concatenation( char dest[200][13] ) {
// loop through and concatenation the strings
for(int i=0;i<200;i+=2) {
myStrCat(dest[i],dest[i+1]); // mystrcat is equalto strcat()
[Code] .....
View 4 Replies
View Related
Dec 16, 2013
[URL] ....
My calculation function will not work like i wanted it to. It gives me 0 or a crazy number.
this is the function here:
the entire code is on the link:
double calculations(data&avgs) //Calculates the students grade into a final grade
{
int avg1;
int avg2;
int avg3;
int lab1;
[Code] ....
View 12 Replies
View Related
Apr 8, 2013
This code gets a binary number and change its bits. I have a problem with the "bits_up" function . Why this function not working?
Code:
#include <stdio.h>
#include <stdlib.h>
int bits_up(uint first,uint last,int *ptr);
int main(void)
{
uint first,last,bitUD;
int InputBinNumber[4],updatedNum[4];
[Code] ....
View 5 Replies
View Related
May 9, 2013
I tested my count funtion. So my count function is not working properly, it should return 5 because 5 words have prefix "tal," but it is giving me 10. It's counting blank nodes.
This is my main.cpp file
int main() {
string word;
cout<<"Enter a word"<<endl;
cin >> word;
string filename;
[Code] .....
View 9 Replies
View Related
Oct 22, 2013
I've created a function where you can choose any bounds for an array based list (positive or negative, as long as the first position is smaller than the last position). However for some reason when I call the print() function in my application program it doesn't do anything. My print function is technically correct (I still have work to do on the output) but I can't figure out why it wont show anything at all. Below is my header, implementation, and main program files, along with results from running the program.
Header File:
//safearrayType Header File
class safeArrayType {
public:
void print() const;
void insertAt(int location, const int& insertItem);
safeArrayType(int firstPlace=0, int maxPlace = 100);
[Code] ....
ResultsEnter the first bound of yourlist: -3(this was my input)
Enter the last bound of yourlist: 7(this was my input)
Press any key to continue...
View 1 Replies
View Related
Mar 6, 2015
Whenever I put my dll files in the same directory as my main.cpp and use this code, Code: g++ main.cpp -L. -lMyDll it works.
but if my dll files are in the other directory, Code: g++ main.cpp -L/myDlls -lMyDll it won't work. Why is this not working?
View 6 Replies
View Related
Jul 5, 2014
i am currently trying to get SDL working with C language.I am using Cygwin and Sublime text 2.I know and understand general programming, however i am trying to understand how to get SDL working with a file i create i.e test.c. i know to include which i have downloaded
#include <SDL.h>
where do i add the libraries so that i can use them in my program?
View 9 Replies
View Related
Apr 16, 2014
I am writing an irc bot in c++ on linux mint, and its not connecting right for some reason. anyways, heres the link: [URL].... . it was connecting to quakenet before I added the functions, but now it just says connecting... and then quits.
View 12 Replies
View Related