473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

class project

I need to know how i could right a program that will take as input a character and an integer. If the integer is even, then add one to it. Using the for loop to make the output a diamond composed of a character and as wide as the int.
e.i. Enter a character and an integer:
@ 4

@
@@
@@@
@@@@
@@@
@@
@

I would really appreciate it i've been trying to figure it out for the entire weekend
Oct 3 '06 #1
4 2030
Try this out, let me know if it does what you want.

Wasn't sure about the adding one to an even number thing, I might have been mis-reading your question, but this should start you out:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main(int argc, char* argv[])
  6. {
  7.     char symbol;
  8.     int numPrints, i, j;
  9.  
  10.     cout << "Enter symbol: ";
  11.     cin >> symbol;
  12.     cout << endl << endl;
  13.     cout << "Enter Integer: ";
  14.     cin >> numPrints;
  15.     cout << endl << endl;
  16.  
  17.     for (i = 1; i <= numPrints; i++)
  18.     {
  19.         for (j = 1; j <= i; j++)
  20.         {
  21.             cout << symbol;
  22.         }
  23.         cout << endl;
  24.     }
  25.  
  26.     for ( i = numPrints - 1; i > 0; i--)
  27.     {
  28.         for (j = i; j > 0; j--)
  29.         {
  30.             cout << symbol;
  31.         }
  32.         cout << endl;
  33.     }
  34.  
  35.     return 0;
  36. }
  37.  
Anthony
Oct 3 '06 #2
D_C
293 100+
He didn't use (code) tags, so the whitespace was not preserved. He meant
Expand|Select|Wrap|Line Numbers
  1.    @
  2.   @@@
  3.  @@@@@
  4. @@@@@@@
  5.  @@@@@
  6.   @@@
  7.    @
You need two loops, one to do the top half of the diamond, one to do the second half of the diamond. Then each loop needs to first print some spaces, then print that symbol several times.
Expand|Select|Wrap|Line Numbers
  1. string(numberOfSymbol,symbol)
Prints the (char)symbol (int)numberOfSymbol times. I'll pseudocode the printing part.
Expand|Select|Wrap|Line Numbers
  1. // Top half
  2. numSymbols = 1;
  3. while(numSymbols < maxSymbols)
  4. {
  5.   numSpaces = // A function of numSymbols and maxSymbols
  6.   cout << string(numSpaces,' ');
  7.   cout << string(numSymbols,symbol) << endl;
  8.   numSymbols += 2;
  9. }
  10. // Bottom half
  11. while(numSymbols > 0)
  12. {
  13.   numSpaces = // The same function of numSymbols and maxSymbols
  14.   cout << string(numSpaces,' ');
  15.   cout << string(numSymbols,symbol);
  16.   numSymbols -= 2;
  17. }
Oct 3 '06 #3
Ahh, I see - sorry for the confusion. Didn't realize the absence of code tags.

Thanks, D_C, for clearing that up, and answering the question.
Oct 3 '06 #4
thank you for your help
Oct 4 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Nancy | last post by:
I have the following situation and could use some advise. I have a Base Class CreditReport, classes BoatCreditReport and HomeCreditReport Inherit from CreditReport. I would like to have the...
2
by: Rafael Pivato | last post by:
Hi, How can I make two libraries with referencing each other ? --------- Thanks, Rafael Pivato
8
by: Brett Romero | last post by:
I have this situation: myEXE <needs< DerivedClass <which needs< BaseClass Meaning, myEXE is using a type defined in DerivedClass, which inherits from BaseClass. I include a reference to...
5
by: D Witherspoon | last post by:
What is happening is that I have a class (ClassA) that inherits a class (ClassB) which inherits System.Net.Mail.MailMessage Project 1 references Project 2, Project 2 references Project 3. ...
4
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project...
5
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project...
0
by: tony | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. In this user control we have a class...
16
by: Robert Dufour | last post by:
Here's the class code snippet Imports System.Configuration.ConfigurationManager Public Class Class1 Public _strTestSetting As String Public Sub SetTestsetting()
4
by: Alan Mailer | last post by:
Again, I'm new to VB.net and there is something I need help with: Like (I assume) many of us, over time I want to be able to create some VB.net classes that I might want to use in more than one...
5
by: Ohad weiss | last post by:
Hi all, I have a class in project A. At the same solution, I have another project - named project B. I want to write a piece of code in that class from project B that finds the class in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.