Hello all.. i have just joined the forum and i would be quite happy to enhance my programming skills being an active member of this forum, but right now i am on tight schedule. i am a newbie to c++ and have to submit an assignment but i am unable to construct it. Its about for loop ...
please help me ...
#ASSIGNMENT
In this assignment you have to write a program that starts by displaying the following menu to user:
Select one of the following choices:
1. Display an hourglass pattern
2. Display a diamond pattern
3. Display the Nepal flag
4. Display the ladder pattern
When the user selects choice 1, you will ask him/her for the size of pattern and the symbol to be used in the pattern. If user enters a negative number, you should prompt him and re-take input.
For example: If the user enters 11 for size and * for symbol then the following is displayed.
***********
*********
*******
*****
***
*
***
*****
*******
*********
***********
If the user enters 15 for size and # for symbol then the following is displayed.
When the user selects choice 2, you will ask him/her for the size of pattern and the symbol to be used in the pattern. If user enters a negative number, you should prompt him and re-take input.
For example: If the user enters 11 for size and & for symbol then the following is displayed.
When the user selects choice 3, you will ask him/her for the size of pattern and the symbol to be used in the pattern. If user enters a negative number, you should prompt him and re-take input.
For example: If the user enters 6 for size and * for symbol then the following is displayed.
*
**
***
****
*****
******
*****
****
***
**
*
**
***
****
*****
******
*****
****
***
**
*
> if i wont be able to submit this assignment. i ll fail the course :'(
You can be using case statements for the menu. Then from there I assume it would be for loops to get the size right, then the pattern character would be stored as a char.
Go watch some YouTube videos on this all if you don't know or fail, resit then actually learn.
We're not going to do your homework for you, but we'll help you fix problems you have. Can you show us the code you've already written, and be a bit more specific about what you're having a problem with?
Thank you for your response guys. Your point is valid. I can learn this for days or even weeks but right now I have only few hours to submit this task. I promise i am not a leech who always rely on others work. I dont have MS visual or any other compiler at the moment. Its been only two month and 10 lectures i have ever came to know C plus plus. if i could get a tiny idea about running all these programes solo.
Just give me a kick start and i will try to write code by myself. i Ll make for loops for each case and all but just give me a start please.
# include <iostream>
using namespace std;
int main()
{
int i,j,choice ;
cout << "Select one of the following choices:"/n
cout<<"1.Display an hour glass pattern"<<endl;
cout<<"2. Display a diamond pattern"<<endl;
cout<<"3. Display the Nepal flag"<<endl;
cout<<"4. Display the ladder pattern<<endl;
switch (choice){
case 0: cout<<1<<"You have selected 1.Display an hour glass pattern"<<endl; break;
case 1: cout<<2<<"You have selected 2. Display a diamond pattern"<<endl; break;
case 2: cout<<3<<"You have selected 3. Display the Nepal flag"<<endl; break;
case 3: cout<<4<<"You have selected 4. Display the ladder pattern<<endl; break;
}
/////////////////////////
////////////////////////
from here please give me a little more push start and lease do tell it above code is ok ?
no it's not.
you print 5 lines to the screen, and you do not bother getting any user input, so your switch statement will not go as intended as you have not:
1. initialised 'choice'
2. assigned any value to it.
#include <iostream>
#include <cstdlib>
usingnamespace std;
// Diamond
int main ()
{
char esc,icon; // creats a chracter to control exiting the program
do
{
system ("cls");// clears the screen
int a,c,b=0;// Three integers
cout<<"Enter a character\n";// Prompts user to give character input
cin>> icon;// Provides input
cout<<endl;
cout<<"Enter number of lines (Must be positive & odd):\n"<<endl;// Prompts user to give number input
cin>> a;// Provides input
cout<<endl;
if ((a<1)||(a%2==0))// Filters out any number that isn't odd or positive
cout<<"Not a positive odd number! \n"<<endl;
elsewhile( b++<a ) // This while loop is executed "a" times because of the b++
{
c=0;
while(c++<a) // This while loop is executed "a" times because of the c++
{
if(b>(a/2+1))// code for the top half of the diamond
{
if((c>((a/2+1)+a-b))||(c<((a/2+1)-a+b)))// vertically divides the diamond in half
cout<<" ";//Empty space
else
cout<<icon;//Defined char
}
else // code for the bottom half of the diamond
{
if((c>((a/2+1)+b-1))||(c<((a/2+1)-b+1)))// vertically divides the diamond in half
cout<<" ";// empty space
else
cout<<icon;//Defined char
}
}
cout<<endl;
}
cout<<"Try again? (y/n)"<<endl<<endl;// Asks user to retry
cin>>esc;// Takes yes or no input
cout<<endl<<endl;
} while (esc=='y');// reruns the whole thing if the User gave a value of "y"
return 0;
}