No, I understand that. And yes, I have written several programs that have allowed me to use the pow function. I have reason to believe that it has something to do with the compiler. I've tried the same source code on another compiler and the problem was resolved.
However, I'm having a different problem at this point...
At present, the program is for the most part finished, and it successfully converts any positive binary number up to 32 bits into its corresponding decimal form. However, I can't seem to make it user friendly, ie, I can't get it to successfully ask the user whether or not they want to convert bin to dec, or whether or not they want to continue.
I've got to get the program to initially ask whether or not they want to convert from bin to dec, if not the program is supposed to terminate. If so, it's supposed to execute. After it executes, it's supposed to ask the user whether or not they want to try again with another number, and at that point, it's supposed to loop.
Here's the source code:
Code:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
main ()
{
int count = 0, bin, num=0, sum=0;
char forward[32], backward[32], convert, swap, cont;
cout << "This program converts positive integer" << endl;
cout << "binary numbers (up to 32 bits) to decimal." << endl << endl;
cout << "Enter binary number you wish to convert: ";
cont = 'y';
while(cont == 'y' || cont == 'Y')
{
cin >> noskipws >> forward[0];
while(forward[count] != '\n')
{
count ++ ;
cin >> forward[count] ;
}
for ( bin = count-1; bin >= 0 ; bin -- )
{
swap = forward[bin];
backward[num] = swap;
num++;
}
sum = 0;
cout << endl << endl;
for ( num=0; num <= count-1; num++)
{
sum = sum + ((backward[num]-48) * pow(2.0,num));
}
for ( bin = 0; bin <= count-1; bin++)
{
cout << forward[bin];
}
cout << " in decimal is " << sum << endl;
cout << "Continue? (y/n): ";
cin >> cont;
}
}
This code isn't letting me insert a cin before the first cin there with the noskipws. And that includes when it loops after the first run through. If I have a cin before that intial cin there, it just takes whatever value it has stored and reruns or runs that, whether null or with previous results.
...Does anyone know what's wrong with this? Why is this happening?
This should just be a matter of an if/else and a while loop, but it doesn't seem to be working so flawlessly.
Thanks!