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 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);
Code: Complete the program below which converts a binary number into a decimal number. Sample outputs are shown belowComplete the program below which converts a binary number into a decimal number. Sample outputs are shown below.
Sample Output 1:
8-bit Binary Number => 11111111 Decimal Number = 255
Sample Output 2:
8-bit Binary Number => 10101010 Decimal Number = 170
Sample Output 3:
8-bit Binary Number => 101010102 Number entered is not a binary number
#include <iostream> using namespace std; int main() { int num;
I am very new to programming and have been working on a program that can receive decimals or binary numbers and convert them. The decimal --> binary works fine. For some reason I cannot figure out I cannot get the "BinaryToDecimal" function to perform. By putting a "printf" into the for-loop.
Code:
#include <stdio.h>#include <string.h> #include <math.h> char* ReverseString (char _result[]) { int start, end, length = strlen(_result); char swap; for (start = 0, end = length-1; start < end; start++, end--)
I have a code and am asked to modify it so that it will take as input as unsigned binary number up to 16 digits in length and convert it into its equivalent decimal number and output that decimal number.
All I know is that I use library function strlen() in <cstring> to calculate the length of the input string.
I also know I have to use something called pow(2,4);
//pow (); is found in cmath
I was told to use sum = sum >>16-l; (l is the length of />/>
#include <iostream> using namespace std; int main() {
I'm writting an algorithm which equals to std::to_string. The inttostring part is fine, and the decimal_part too. But when the number digits > 5, the program loops infinitely.
#include "stdio.h" #include <stdarg.h> #include <math.h> // Main Function int main(void){ int number; printf(" Please enter a number from 1-10? "); scanf("%d", &number);
[Code] ....
I took the while statement out didn't want that in there.
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.
I need the user to be able to input the number of decimal places they wish to have displayed in the output. Everything works fine as is, I just don't know how to allow for the user to input the number of decimal places they want the output to have.
Code:
#include<stdio.h> #include<math.h> #define PI 3.141592654 int main(void) { //Local Declarations int x; //desired number of decimal places float radius; //radius of circle float circumference; //circumference of circle
How to return the value after the decimal point. For example:if two integer numbers are 3, 4 then (3+4)/2 is 3.5 the 5 after the decimal point is to be returned. if suppose it is 34.456 i have to return 456.
I nead to write a program that convert an octal number to decimal number, I thought I did it right but it doesn't work.. I have to use in the first for loop as it is because it is part of the instructions (student homework).
What would be the best way to remove the decimal point from a float number? For instance if I have a float number .2546 I would like to be able to remove the dot and use just the number (int) 2546 for some calculations.
Maybe, convert to string than remove the first character from the string than convert the string back to an int?
My size of binary file is 1920 KB and my struct size is 124 kb. now to find number of records in file I divided 1920/124 and it gives me 15.4.... do I add 1 to 15.4 and make it 16 or do i take it as 15?
Now as you can see that all the binary output is in a[] but how do I get it into a string so that I can use something like printf("%s",string) and get the binary output ?
I'm trying to pass a decimal number to a function and convert it to binary and return it and print it out in main. But it prints out 1011 and then seg faults...not sure where it's tripping up
Code: int main(){ char* binNum = decToBin(25); int i = 0; while(binNum != NULL){
You enter decimal number into the program and what base you want. The integer part of the decimal is being handled fine, but the decimal is not.
For example, I enter 15.6847 and base 10, which means I'm going from base 10 to base 10. It spits out 68469999999999 for the decimal part. (Do not worry about the first block of numbers. The second block seperated from the first by a space is where the decimal will appear in order.)
#include <iostream> #include <string> #include <math.h> using namespace std; int baseConverter(int, int, int *, int *);
Store the result into an array D of 8 elements. Your program should show the decimal numbers for every binary number. Print screen of 6 answers. This means you should try your program six times with different numbers in every run and show the printed screen result.
So I have a template, part of a larger code, that is designed to calculate the number of multiplications it took to reach a certain number. The problem is, whenever I execute the program, mults is always printing out a strange number, perhaps its actual address.
template <class T> T power3(T x, unsigned int n, unsigned int& mults) { if (n == 0) return 1; if (n == 1) return x; if (n == 2){