carnage 24 Junior Poster in Training

awesome. didn't know there's a library for that
(well i just started learning different programming languages so what do you expect lol)

in the <bitset> library,can i convert any number system to another?
i tried googling but i don't even get the process on how that binary input is converted into decimal.


OT: instead of creating another thread,i'll just ask this simple question here

is there a way i can fix this long line:

cout<<"\n               ##                                 \n  ## # # ###  #   ## ### ###      ## ### ###  ## \n  #  # # #   ### # # #   ##      # # #   ##  # # \n ##  ### #    #  ### ### ###     ### #   ### ### \n             ##                                  \n\n              #           #       #          \n     ###  ##  #  ### # #  #   ## ### ### ### \n     #   # #  #  #   # #  #  # #  #  # # #   \n    ### ###  ## ### ###  ## ###  ## ### #"<<endl<<endl;

is there an escape sequence that lets me divide this long single line into multiple lines
BUT only affects the source code?

carnage 24 Junior Poster in Training

i would like to create a program that converts a number system to another

i found few ideas on how to do this but lacks explanation so i can't figure out 'how it worked'.
found that 'for loop' over the net,did some editing then applied it in a program.

here's a code

#include <iostream.h>
#include <math.h>


int main()
{
    int bin,n,r,x;
    char a;//looping
    
do
  {
    int s=0;
    system("cls");
    cout<<"Number System Conversion Program"<<endl;
    cout<<"\nEnter binary: ";
    cin>>bin;
    
    n=bin;
    for(x=0;n!=0;x++)
    {
        r=n%10;//this is the part 
        s=s+r*(int)pow(2,x);//im having a hard time
        n=n/10;//to figure out
    }
    cout<<"binary: "<<bin<<"\ndecimal: "<<s;
    cout<<"\nenter new number?[y/n]: ";
    cin>>a;
}while((a=='y')||(a=='Y'));
system("cls");
}

1)can someone be kind enough to explain that part in the 'for loop'?

2)whenever i enter 1000000000000000,the program stops responding.
i tried to declare everything as unsigned int or even unsigned long but still same problem.

carnage 24 Junior Poster in Training

1)thanks it worked. it's ok but it'd probably be better if the program treats an input like '12' as with 'default'.

2)i tried solving this one having a condition but doesn't work:

switch (figure)
    {
           case '1': //figure is circle
           do
           {
           
           system("cls");
           cout<<"input radius: ";
           cin.clear();
           cin>>rad;
           }while ((rad<-32767)||(rad>32767));

if i entered for example 'a', program starts to 'blink' and not respond lol

carnage 24 Junior Poster in Training

i declared figure as character

carnage 24 Junior Poster in Training

here's my code:

cin>>figure;
switch (figure)
    {
           case '1': //figure is circle
           system("cls");
           cout<<"input radius: ";
           cin>>rad;
           cout<<"\nsurface area of your circle is "<<pi*rad*rad;
           break;
           case '2': //figure is rectangle
           system("cls");
           cout<<"input length: ";
           cin>>length;
           cout<<"\ninput width: ";
           cin>>width;
           cout<<"\nsurface area of your rectangle is "<<length*width;
           break;
     }

1)when i input for example "12" at CIN>>FIGURE,the program goes to case1 then won't ask the user to input a radius and treats second digit,which is "2",as it's radius.

question: how can i solve this one?

2)the program exits immediately when the user enters a non-numeric value on an input that needs to be computed.

question:how can i make the program ask the user to input a new value instead of exiting?