C/C++ :: Check If A Number Has Decimal Place

May 31, 2014

I'm trying to make a program to check if a number has decimal place, for instance: 1.34(yes), 1.0(no), 3.45(yes), 5.0(no).

Code:

#include <stdio.h>
#define LENGTH 4
int main( void ) {
int i;
float a[LENGTH];
for(i=0; i < LENGTH; i++) {
scanf("%f", &a[i]);

[Code] ...

I'm getting this output, why?

Quote

error: invalid operands of types "float" and "int" to binary "operator%"

View 3 Replies


ADVERTISEMENT

C :: ROM BIOS Programming - Accept Row Number From User And Place Cursor To The Beginning Of That Row

Nov 27, 2013

How do I write a ROM BIOS routine which accepts a row number from the user and place the cursor to the beginning of the row number which the user gave?

View 2 Replies View Related

C++ :: Input Decimal Number And Output To Be Number Scientific Notation

Apr 26, 2013

I need to write a code in c++ , to input decimal number and the output to be number in Scientific notation with 32 bits .

View 1 Replies View Related

C++ :: Convert 8-digit Binary Number To Decimal Number?

Jul 6, 2013

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;

[code]....

View 2 Replies View Related

C++ :: Convert Binary Number Into A Decimal Number

Jul 5, 2013

Here's the part of the codes where I tried to use boolean expression:

Code:
#include <iostream>
using namespace std;
int main() {
int num;
cout << "8-bit Binary Number=";
cin >> num;

[Code] .....

How can I get started with the body?

View 7 Replies View Related

C++ :: Convert Binary Number Into Decimal Number?

Jul 5, 2013

Here's the part of the codes where I tried to use boolean expression:

#include <iostream>
using namespace std;
int main()

[Code].....

May I know that how can I get started with the body?

View 5 Replies View Related

C :: Binary Number To Decimal

Mar 30, 2014

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--)

[code]....

View 2 Replies View Related

C/C++ :: Binary Number Into Decimal?

Sep 10, 2014

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() {

[Code]....

View 4 Replies View Related

C++ :: Get Fraction For Any Decimal Number In Variable?

Jun 9, 2013

How do i get the fraction for any decimal number in a variable?

Code: Code: #include<iostream>
using namespace std;
int main()
{
double x = 1/6;
cout << x;
cin.get();
}

View 1 Replies View Related

C++ :: Algorithm To Get The Decimal Part Of A Number?

Jun 12, 2014

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 <iostream>
#include <string>
#include <algorithm>

[Code]...

In this code, the program runs ok. But try to add a 5 at decimal_part. What should I do to get this 'decimal_part' ok?

View 6 Replies View Related

C/C++ :: Convert Decimal Number To Roman?

Sep 17, 2014

#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.

View 2 Replies View Related

C++ :: Can't Output Decimal Number From A Function Result

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

C :: User Defined Number Of Decimal Places?

Sep 2, 2013

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

[Code] .....

View 2 Replies View Related

C :: How To Calculate Number Of Digits After Decimal Point

May 24, 2014

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.

View 11 Replies View Related

C++ :: Program To Convert Octal Number To Decimal

Mar 27, 2013

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).

#include <iostream>
#include <math.h>
using namespace std;
void main() {
double numOfDig, num, newNum;

[Code] ....

View 1 Replies View Related

C++ :: Remove Decimal Point From Float Number?

Dec 16, 2013

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?

View 2 Replies View Related

C++ :: Number Of Records In Binary File Is In Decimal?

Oct 9, 2014

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?

View 9 Replies View Related

C :: Convert Decimal Number To Binary And Store It In A String

Apr 16, 2014

I want to convert a decimal number to binary and store it in a string so that I can use that binary output for later computation. Here is what I did

Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()

[Code] ....

​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 ?

View 7 Replies View Related

C :: Pass Decimal Number To Function And Convert It To Binary?

Feb 26, 2013

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){

[Code].....

View 6 Replies View Related

C++ :: Enter Decimal Number Into Program And Required Base

Oct 12, 2013

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 *);

[Code] ....

View 2 Replies View Related

C++ :: Random Number Generator Decimal To Binary System 0 To N

Mar 22, 2013

#include <iostream>
#include <stdlib.h>
using namespace std;

[Code]....

View 1 Replies View Related

C/C++ :: How To Convert Byte Array With Hex Number To Equivalent Decimal Value

Sep 18, 2012

I tried to convert byte array with hex to equivalent decimal value as follows but it gives me unexpected results:

byte hex_arr[] = { 0x00, 0x01, 0xab, 0x90};
unsigned long i=0;
i = hex_arr[3] + (hex_arr[2] << 8) + (hex_arr[1] << 16) + (hex_arr[0] << 24);
the output is 4294945680
Correct output should be 109456

but when I try with byte hex_arr[]={0x00,0x00,0x0f,0xff};

it gives correct out put 4095

the correct output works until the hex values is {0x00,0x00,0x7f,0xff}

View 8 Replies View Related

Visual C++ :: Converting Decimal Number Given By User To Binary?

Dec 19, 2014

Write a C++ program that adds three binary numbers of 8-bit each. Every number is stored into an array of 8 elements.

Example:

Array A
0 1 2 3 4 5 6 7
0 1 1 0 1 1 1 0
+
Array B
0 1 2 3 4 5 6 7
0 1 1 0 1 1 1 0
+
Array C
0 1 2 3 4 5 6 7
0 1 1 0 1 1 1 0

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.

View 5 Replies View Related

C :: Converting Decimal Number To Any Base Then Find Ones And Twos Complement

Oct 10, 2014

I have the code working on converting a decimal number to base 1 through 16. I need getting the code to output the one's and two's complement.

Code:
#include <stdio.h>
int main(void) {
char base_digits[16] =
{'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

int converted_number[64];
long int number_to_convert;
int next_digit, base, index=0, a;

/* get the number and base */

[Code] ....

View 8 Replies View Related

C++ :: Negative Number Check

Sep 30, 2013

The code on lines 44-53 is suppose to display a message when the user enter a negative number, however, when a correct positive number is entered the message is display again.

#include<iostream>
#include<cctype>
using namespace std;
int main() {
char carType;
int A, B, C;

[Code] ....

View 2 Replies View Related

C++ :: CPP Program To Check Whether A Number Is Palindrome Or Not?

Feb 12, 2014

I could not find the mistake in this program....

Code:
//cpp program to check whether a number is palindrome or not
#include<iostream.h>
#include<conio.h>
//the class
class palindrome

[Code] ....

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved