C++ 'if' statement displays every option. Outputs show one Above the other and not one followed by the other. -


first , foremost, newbie when comes c++ try understand struggle. so, problem. have assignment have input 4-digit number , each of digits has represented in form of stars. thing can use have learned till can't use arrays etc while,if,else , basic statements/loop. wondering wrong code because when input 4-digit number doesn't show 4 digits shows every single number in star form 1 above other. can tell me doing wrong because cannot understand anymore. have suggestions how can display numbers chosen not 1 above other, 1 followed other. thank guys in advance! appreciated!

#include <iostream> using namespace std; /* run program using console pauser or add own getch,  system("pause") or input loop */  int main(int argc, char** argv) { int a,b,c,d; int a1,b1,c1,d1;  cout<<"input 4 digit number:"<<endl; cin>>a;  a1 = / 1000; b  = % 1000;  b1 = b / 100; c  = b % 100; c1 = c / 10; d  = c % 10; d1 = d / 1;  if (a1==1)  cout<<"\n";  cout<<"    **  \n"; cout<<"  ** ** \n"; cout<<" **  ** \n"; cout<<"     ** \n"; cout<<"     ** \n"; cout<<"     ** \n"; cout<<"\n";   if (a1==2) cout<<"\n";     cout<<"   ****  \n"; cout<<" **   ** \n"; cout<<"  *  **  \n"; cout<<"    **   \n"; cout<<"   **    \n"; cout<<"  *****  \n"; cout<<"\n";      if (a1==3) cout<<"\n";   cout<<"   *****   \n"; cout<<"       *   \n"; cout<<"    ****   \n"; cout<<"       *   \n"; cout<<"   *****   \n"; cout<<"\n";     if (a1==4) cout<<"\n";    cout<<"  **   **   \n"; cout<<"  **   **   \n"; cout<<"   ******   \n"; cout<<"       **   \n"; cout<<"       **   \n"; cout<<"\n";   if (a1==5)  cout<<"\n";     cout<<"  ******   \n"; cout<<"  **        \n"; cout<<"  ******   \n"; cout<<"       **    \n"; cout<<"  *****      \n"; cout<<"\n";   if (a1==6)  cout<<"\n";     cout<<"      ***   \n"; cout<<"     **     \n"; cout<<"    ****    \n"; cout<<"   **   **  \n"; cout<<"  **    **  \n"; cout<<"   *****    \n";  cout<<"\n";       if (a1==7)  cout<<"\n";     cout<<"  ******    \n"; cout<<"      **    \n"; cout<<"     **     \n"; cout<<"    **      \n"; cout<<"   **       \n"; cout<<"  **        \n"; cout<<"\n";   if (a1==8)  cout<<"\n";     cout<<"   ***   \n"; cout<<" **  **   \n"; cout<<"   **      \n"; cout<<"   **      \n"; cout<<" **  **   \n"; cout<<"   ***   \n";         cout<<"\n";  if (a1==9)  cout<<"\n";  cout<<" *******   \n"; cout<<" **   **   \n"; cout<<" **   **   \n";   cout<<" *******   \n"; cout<<"      **   \n"; cout<<"      **   \n";   cout<<"\n";        if (b1==0)     cout<<"\n";      cout<<"   ***   \n";     cout<<"  ** **   \n";     cout<<"  ** **   \n";            cout<<"  ** **   \n";            cout<<"  ** **   \n";     cout<<"   ***    \n";     cout<<"\n";      if (b1==1)     cout<<"\n";      cout<<"    **  \n";     cout<<"  ** ** \n";     cout<<" **  ** \n";     cout<<"     ** \n";     cout<<"     ** \n";     cout<<"     ** \n";     cout<<"\n";      if (b1==2)     cout<<"\n";      cout<<"   ****  \n";     cout<<" **   ** \n";     cout<<"  *  **  \n";     cout<<"    **   \n";     cout<<"   **    \n";     cout<<"  *****  \n";     cout<<"\n";       if (b1==3)     cout<<"\n";      cout<<"   *****   \n";     cout<<"       *   \n";     cout<<"    ****   \n";     cout<<"       *   \n";     cout<<"   *****   \n";     cout<<"\n";      if (b1==4)     cout<<"\n";      cout<<"  **   **   \n";     cout<<"  **   **   \n";     cout<<"   ******   \n";     cout<<"       **   \n";     cout<<"       **   \n";     cout<<"\n";      if (b1==5)     cout<<"\n";      cout<<"  ******   \n";     cout<<"  **        \n";     cout<<"  ******   \n";     cout<<"       **    \n";     cout<<"  *****      \n";     cout<<"\n";      if (b1==6)     cout<<"\n";      cout<<"      ***   \n";     cout<<"     **     \n";     cout<<"    ****    \n";     cout<<"   **   **  \n";     cout<<"  **    **  \n";     cout<<"   *****    \n";     cout<<"\n";      if (b1==7)     cout<<"\n";      cout<<"  ******    \n";     cout<<"      **    \n";     cout<<"     **     \n";     cout<<"    **      \n";     cout<<"   **       \n";     cout<<"  **        \n";     cout<<"\n";      if (b1==8)     cout<<"\n";      cout<<"   ***   \n";     cout<<" **  **   \n";     cout<<"   **      \n";     cout<<"   **      \n";     cout<<" **  **   \n";     cout<<"   ***   \n";             cout<<"\n";      if (b1==9)     cout<<"\n";      cout<<" *******   \n";     cout<<" **   **   \n";     cout<<" **   **   \n";       cout<<" *******   \n";     cout<<"      **   \n";     cout<<"      **   \n";     cout<<"\n";          if (c1==0)         cout<<"\n";          cout<<"   ***   \n";         cout<<"  ** **   \n";         cout<<"  ** **   \n";                cout<<"  ** **   \n";                cout<<"  ** **   \n";         cout<<"   ***    \n";         cout<<"\n";          if (c1==1)         cout<<"\n";          cout<<"    **  \n";         cout<<"  ** ** \n";         cout<<" **  ** \n";         cout<<"     ** \n";         cout<<"     ** \n";         cout<<"     ** \n";         cout<<"\n";           if (c1==2)         cout<<"\n";          cout<<"   ****  \n";         cout<<" **   ** \n";         cout<<"  *  **  \n";         cout<<"    **   \n";         cout<<"   **    \n";         cout<<"  *****  \n";         cout<<"\n";           if (c1==3)         cout<<"\n";          cout<<"   *****   \n";         cout<<"       *   \n";         cout<<"    ****   \n";         cout<<"       *   \n";         cout<<"   *****   \n";         cout<<"\n";          if (c1==4)         cout<<"\n";          cout<<"  **   **   \n";         cout<<"  **   **   \n";         cout<<"   ******   \n";         cout<<"       **   \n";         cout<<"       **   \n";         cout<<"\n";          if (c1==5)         cout<<"\n";          cout<<"  ******   \n";         cout<<"  **        \n";         cout<<"  ******   \n";         cout<<"       **    \n";         cout<<"  *****      \n";         cout<<"\n";          if (c1==6)         cout<<"\n";          cout<<"      ***   \n";         cout<<"     **     \n";         cout<<"    ****    \n";         cout<<"   **   **  \n";         cout<<"  **    **  \n";         cout<<"   *****    \n";         cout<<"\n";          if (c1==7)         cout<<"\n";          cout<<"  ******    \n";         cout<<"      **    \n";         cout<<"     **     \n";         cout<<"    **      \n";         cout<<"   **       \n";         cout<<"  **        \n";         cout<<"\n";          if (c1==8)         cout<<"\n";          cout<<"   ***   \n";         cout<<" **  **   \n";         cout<<"   **      \n";         cout<<"   **      \n";         cout<<" **  **   \n";            cout<<"   ***   \n";                 cout<<"\n";          if (c1==9)         cout<<"\n";          cout<<" *******   \n";         cout<<" **   **   \n";         cout<<" **   **   \n";           cout<<" *******   \n";         cout<<"      **   \n";         cout<<"      **   \n";                       cout<<"\n";              if (d1==0)             cout<<"\n";              cout<<"   ***   \n";             cout<<"  ** **   \n";             cout<<"  ** **   \n";                    cout<<"  ** **   \n";                    cout<<"  ** **   \n";             cout<<"   ***    \n";             cout<<"\n";               if (d1==1)             cout<<"\n";              cout<<"    **  \n";             cout<<"  ** ** \n";             cout<<" **  ** \n";             cout<<"     ** \n";             cout<<"     ** \n";             cout<<"     ** \n";             cout<<"\n";              if (d1==2)             cout<<"\n";              cout<<"   ****  \n";             cout<<" **   ** \n";             cout<<"  *  **  \n";             cout<<"    **   \n";             cout<<"   **    \n";             cout<<"  *****  \n";             cout<<"\n";                if (d1==3)             cout<<"\n";              cout<<"   *****   \n";             cout<<"       *   \n";             cout<<"    ****   \n";             cout<<"       *   \n";             cout<<"   *****   \n";             cout<<"\n";              if (d1==4)             cout<<"\n";              cout<<"  **   **   \n";             cout<<"  **   **   \n";             cout<<"   ******   \n";             cout<<"       **   \n";             cout<<"       **   \n";             cout<<"\n";              if (d1==5)             cout<<"\n";              cout<<"  ******   \n";             cout<<"  **        \n";             cout<<"  ******   \n";             cout<<"       **    \n";             cout<<"  *****      \n";             cout<<"\n";              if (d1==6)             cout<<"\n";              cout<<"      ***   \n";             cout<<"     **     \n";             cout<<"    ****    \n";             cout<<"   **   **  \n";             cout<<"  **    **  \n";             cout<<"   *****    \n";             cout<<"\n";              if (d1==7)             cout<<"\n";              cout<<"  ******    \n";             cout<<"      **    \n";             cout<<"     **     \n";             cout<<"    **      \n";             cout<<"   **       \n";             cout<<"  **        \n";             cout<<"\n";              if (d1==8)             cout<<"\n";              cout<<"   ***   \n";             cout<<" **  **   \n";             cout<<"   **      \n";             cout<<"   **      \n";             cout<<" **  **   \n";                cout<<"   ***   \n";                     cout<<"\n";              if (d1==9)             cout<<"\n";              cout<<" *******   \n";             cout<<" **   **   \n";             cout<<" **   **   \n";               cout<<" *******   \n";             cout<<"      **   \n";             cout<<"      **   \n";             cout<<"\n";              return 0; 

}

if allows conditionally execute the following statement. after statement follows condition not part of if , executed regardless of condition. include multiple statements, use braces define compound statement.

your example preforms following :

if (a1==1) {     // executes if a1==1     cout<<"\n";  }  // executes cout<<"    **  \n"; cout<<"  ** ** \n"; cout<<" **  ** \n"; cout<<"     ** \n"; cout<<"     ** \n"; cout<<"     ** \n"; cout<<"\n"; 

you seem trying preform :

if (a1==1) {     // executes if a1==1     cout<<"\n";      cout<<"    **  \n";     cout<<"  ** ** \n";     cout<<" **  ** \n";     cout<<"     ** \n";     cout<<"     ** \n";     cout<<"     ** \n";     cout<<"\n"; } 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -