| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
General - Help with program!!
my objective:
ask the user for a number, and for a character then print out the character that many times How do i print the characters all on the same line? |
|
#2
|
||||
|
||||
|
Quote:
... by not adding newlines between them? (or not having so many it has to wrap them to display them all.)
__________________
Quote:
|
|
#3
|
|||
|
|||
|
Quote:
I need to make it so that if i enter say 15 * it will print out ********** ***** my program is like this: int main () { int number; int line; char character; cout << "please enter a positive integer" << endl; cin >> number; cout << "please enter a character" << endl; if (number > 0) { for ( int line=0; line < number; line++) { cin >> character; } for (int line=0; line < number; line++) { if (line%10==0);cout << "/n"; {cout << character; } } |
|
#4
|
||||
|
||||
|
Your code is effectively asking for the same number of letters that you're going to print, and will use the last of them. Why you have that first for loop is beyond me.
|
|
#5
|
|||
|
|||
|
Quote:
I'm trying to get it to print only ten per line now I'm stuck with it only printing the correct amount of letters and not stopping at only ten per line. I am VERY new to this int number; int line; char character; cout << "please enter a positive integer" << endl; cin >> number; cout << "please enter a character" << endl; cin >> character; if (number > 0) for ( int j=0; j > character; j++) { cout << character << endl; number = number - 10; } for (int i; i < number; i++) { cout << character; if (i%9==0); } |
|
#6
|
||||
|
||||
|
Code:
for (int i=0; i<number; i++) {
if (i%10) { cout << character; }
else { cout << '\n' << character; }
}
This is similar to what you tried to do in the post above, if (line%10==0);cout << "/n"; but that extra ; prevents it from working as it should. (Not that the full program would work with that.) |
|
#7
|
|||
|
|||
|
Quote:
Thank you very much, I've finally got it! |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > General - Help with program!! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|