Hi ,
i wrote this program i am having problem its giving me error whenever i hit case 1 can any1 give me a suggestion what i am doing wrong

#include


 <iostream> 

using


 namespace std;
 
#include


 <string>
 




int main() {
 




int y;
 


int x;
 


int ur_choice = 0;
 


int s;
 


int blank;
 


do {
 


bool test = true; 



while (test){
 
cout<< 

" Menu : " << endl;
 
cout<< 

" 1. " << " Triangle 1 " << endl;
 
cout<< 

" 2. " << " Triangle 2 " << endl;
 
cout<< 

" 3. " << " Triangle 3 " << endl;
 
cout<< 

" 4. " << " Triangle 4 " << endl; 

cout<< 

" 5. " << " Quit " << endl; 

cout<< endl;
 


if (cin >> ur_choice)
 
{
 
test = 

false; 

}

else
 
{
 
cin.clear();
 
string str;
 
cin >> str; 

cout<< 

" Invalid Entry "<<endl;
 
}

 }
 


if (ur_choice<=0 && ur_choice <=5)
 
{
 


while (!done)


 
{

 cout<< 

" Enter triangle size : ";
 
cin>> s;
 
}
 




switch (ur_choice) 

{
 


case 1: for ( y = s; y >= 1; y--)
 
{
 


for ( x = 1; x <= y; x++)
 
{
 
cout<< 

"*";
 
}
 
cout<< endl; 

}
 


break;



case 2: for ( y = 1; y <= s; y++) 

{
 


for(blank = (y -1); blank > 0; blank--)
 
{
 
cout<< 

" ";
 
}



for ( x = s; x >= y; x--) 

{
 
cout<< 

"*"; 

}
 
cout << endl;
 
}
 


break; 



case 3: for ( y = 1; y <= s; y++)
 
{
 


for ( x = 1; x <= y; x++)
 
{
 
cout<< 

"*"; 

}
 
cout<< endl; 

}
 


break;



case 4: for ( y = 1; y <= s; y++) 

{
 




for ( blank = s; blank > y; blank--) 

{
 
cout<< 

" ";
 
}



for(x = y; x > 0; x--) 

{
 
cout<< 

"*"; 

}
 
cout << endl;
 
}
 


break; 



case 5: cout<< "Have a nice day :D"<<endl;
 


break;
 




default: cout<< " Invalid option" << endl; 



break;
 


}
 
} 

while (ur_choice != 5);
 




char v;
 
cin>>v;
 


return 0; 

}

1) What error are you getting?
2) Can you convert the inner portions of the case statements to function calls instead?
Grouping your code into functions will probably reveal the flaw or oversight.

Edited 5 Years Ago by thines01: typo

This article has been dead for over six months. Start a new discussion instead.