Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Binary to Decimal task

$
0
0
Hi :)this is my codes, we are suppose to convert binary to decimal without using array, and use a data file as input and keep tack of valid input's answers.
#include <fstream>
#include <iostream>

using namespace std;

float BtoD (int, int);
float average (int);

	int bit;
	int dec= 0;
	int ave= 0;
	int sum = 0;

float BtoD( int bits, int decimal)
{
	ifstream input;
	
	input.open ("bin.dat");
	int bin = 0;
	

	char check;
	
	
	if (!input)
	{
		cout<< "Error,the date file is not in that file"<< endl;
		return 1;
	}

	while (check= input.peek() != EOF)
	{
		input >> bit;
		cout << bit << " ";  //check to see if bit number is entered.

		for (int i = 1; i <= bits; i ++)
		{
			input >> binary;
			cout<< binary< " "; //check to see if binary number is entered.
		}

	}
	
	return 0; //will edit once above is done
}

int main ()
{
BtoD(bits, decimal);
	average = Average (bits);
	cout << " the Average of the vaild numbers is " << average << endl;

	return 0;
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>