quick cout question

im trying to cout a "%" on the same line, immediately after a cin.

my coding example:

cout << "Price increase: ";
cin >> increaseRate;
cout << "%";


displays:
Price increase: XX
%

BUT

i would like the "%" sign to display on the same line, immediately after, the cin. is this possible? i've tried cin.ignore('\n'); unsuccesfully.

i want it to look like:

Price increase: XX%

thanks for any help!

Last edited on
I don't really know, but this works. Instead of adding it on, it actually clears the screen with the new sentence.
1
2
3
4
cout << "Price increase: ";
    cin >> increaseRate; 
    system("CLS");
    cout << "Price increase: " << increaseRate << "%" << endl;
thanks! that's little rough for what I'm trying to do though. i will definitely add system("CLS"); to my bag of tricks for later.

from what I've learned so far, i think it's in cin's nature to display the '\n' once the user inputs the data. i think i might have to use a different type of input stream, or figure a way to consume the '\n' without displaying it....

(i'm fairly new to all this, so please forgive me if i'm wording things strangely)
Last edited on
I wouldn't suggest system("CLS");

system("anything"); statements are slow, OS-Dependent, and is disliked by AV software. (Quoted from Duaos)

Try using this instead:
1
2
3
4
cout << "Price increase: ";
cin >> increaseRate; 
cout << string( 100, '\n' );
cout << "Price increase: " << increaseRate << "%" << endl;


Last edited on
thanks for the tip. i wasn't aware i could cout << string( 100, '\n');

however it's still a little rough for what i'm trying to do. i have important information displayed i don't want to lose above the user input.
Topic archived. No new replies allowed.