Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,176 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,389 people online right now. Registration is fast and FREE... Join Now!




making table

 
Reply to this topicStart new topic

making table, printing '*'

srw8r3
7 Jul, 2008 - 12:09 AM
Post #1

New D.I.C Head
*

Joined: 6 Jul, 2008
Posts: 2

cpp
 if(x<=i) {
printf("*");
x++=1;
}


trying to get a continous line of * that correspond to an inputed value
i is the input

Mod Edit:
Please code.gif
Thanks, gabehabe smile.gif
User is offlineProfile CardPM
+Quote Post

brainy_creature
RE: Making Table
7 Jul, 2008 - 12:24 AM
Post #2

D.I.C Head
**

Joined: 7 Aug, 2006
Posts: 174



Thanked: 1 times
My Contributions

hey either you can use x++ or use x+=1

User is offlineProfile CardPM
+Quote Post

chuck981996
RE: Making Table
7 Jul, 2008 - 12:39 AM
Post #3

New D.I.C Head
*

Joined: 3 Jul, 2008
Posts: 9


My Contributions
Do you mean you want infinite *'s when the user presses i, or the user types in something and then one asterisk is generated for each character.

here is the code for infite *'s (I'm writing this of the top of my head so excuse me for mistakes)

CODE

#include <iostream>
using namespace std;

int main()
{
    char a;
    cout << “Press i..... ";
    cin << a;
    if (a == "i")
    {
        while (a == "i") cout << "*";
    }
    else cout << "That wasn't i!";
    return 0;
}


I'm not going to write the whole code for the one asterisk per character because I fear you use C and I use C++. However, here is code that counts the amount of characters.

CODE

#include <iostream>
using namespace std;

int main()
{
    char a;
    cout << “Press i..... ";
    cin << a;
    if (a == "i")
    {
        while (a == "i") cout << "*";
    }
    else cout << "That wasn't i!";
    return 0;
}



Hope this helps. smile.gif

User is offlineProfile CardPM
+Quote Post

chuck981996
RE: Making Table
8 Jul, 2008 - 03:50 AM
Post #4

New D.I.C Head
*

Joined: 3 Jul, 2008
Posts: 9


My Contributions
Sorry for the double post, but that^^ code doesn't work tongue.gif(the one for the infinite asterisks) here is the updated promised to work one:

CODE

#include <iostream>
using namespace std;

int main()
{
    string a;
    cout << "Press i..... ";
    cin >> a;
    if (a == "i")
    {
        while (a == "i") cout << "*";
    }
    else cout << "That wasn't i!";
    return 0;
}


User is offlineProfile CardPM
+Quote Post

polymath
RE: Making Table
8 Jul, 2008 - 09:07 AM
Post #5

D.I.C Regular
Group Icon

Joined: 4 Apr, 2008
Posts: 415



Thanked: 4 times
Dream Kudos: 500
My Contributions
Will you people actually help him/her?! If they are trying to make a table than most likely infinate *s will not help much!

Code for given int i, print out i astrixes:
CODE

int i;
//your interface and i/o, the user inputs i (like 2, for example)
for (;i>0;i--) {
   printf("*");
}
printf("\n");


But if you want infinite astrixes in C:
CODE

while(1) printf("*");


That wasn't too hard.


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 10:50AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month