I am coding a program that converts a binary number into decimal number by doubling (Refer to: https://www.wikihow.com/Convert-from-Binary-to-Decimal#Using_Doubling_sub).
If the user input is something other than 1 or 0, then its not a binary number, under that circumstance I want the loop to "break" and say something like: "Oops! Binary numbers have only 1 or 0". If not "then" the loop should continue.
Refer to the code given below for more info:
#include <iostream>
#include <iterator>
using namespace std;
int main(){
int digitsINbinNum;
cout << "If you don't mind. Please enter the number of digits in your binary number: ";
cin >> digitsINbinNum;
int binArray[digitsINbinNum];
cout << "Enter the binary number: ";
for(int digits = 0; digits != digitsINbinNum; ++digits){
cin >> binArray[digits];/*<-----------Here's the part where I am trying to do that*/
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire