Solved

An easy question

Posted on 1998-10-08
7
213 Views
Last Modified: 2010-04-02
If the user inputs 1, 10, 12 , the output of the following program are:
           1: *
*******10: **********
*******12: ************

How can I get the following output?
       1: *
     10: **********
     12: ************

 

#include <iostream.h>
#include <iomanip.h>
int main(){
    int a,b,c;
    cout << "Please enter three integers:" ;
    cin >> a >> b >> c ;
    cout <<setw(9) <<  a << ": " << setw(a+1) << setfill('*') << endl
             <<setw(9) <<  b << ": " << setw(b+1) << setfill('*') << endl
             <<setw(9) << c <<": " << setw(c+1) << setfill('*') << endl;
   
    return 0;
}
0
Comment
Question by:CG
  • 3
  • 3
7 Comments
 
LVL 1

Expert Comment

by:Grailman
ID: 1174703
cout << a << ": " << setw(a+1) << setfill('*') << endl
       << b << ": " << setw(b+1) << setfill('*') << endl
       << c <<": " << setw(c+1) << setfill('*') << endl;
       
     
0
 

Author Comment

by:CG
ID: 1174704
Sorry, your answer is not correct. Here is your output:
1: *
10: **********
12: ************
I need the output :
       1: *
     10: **********
     12: ************
0
 

Author Comment

by:CG
ID: 1174705
I'm glad that I have solved my problem.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Accepted Solution

by:
dinom earned 10 total points
ID: 1174706
#include <iomanip.h>
#include <iostream.h>

int main(){

int a,b,c;
cout << "Please enter three integers:" ;
cin >> a >> b >> c ;
cout <<setw(2) <<a << ": " << setw(a+1) << setfill('*') << endl
<<setw(2) <<b << ": " << setw(b+1) << setfill('*') << endl
<<setw(2) << c <<": " << setw(c+1) << setfill('*') << endl;
 
return 0;
}
0
 

Expert Comment

by:dinom
ID: 1174707
I'm sorry, didn't realize you needed the leading spaces, this should fix that.

#include <iomanip.h>
#include <iostream.h>

int main(){

int a,b,c;
cout << "Please enter three integers:" ;
cin >> a >> b >> c ;
cout << "    " <<setw(2) <<a << ": " << setw(a+1) << setfill('*') << endl
<< "    " <<setw(2) <<b << ": " << setw(b+1) << setfill('*') << endl
<< "    " <<setw(2) << c <<": " << setw(c+1) << setfill('*') << endl;
 
return 0;
}

0
 

Author Comment

by:CG
ID: 1174708
If the user inputs number 100, your program will not be correct.
0
 

Expert Comment

by:dinom
ID: 1174709
Why? Because the screen isn't 100 chars wide?  I don't remember reading anything in the specs that said the goofy program had to handle input of 100.  The numbers given were 1, 10, 12.  How can you expect me to write a program to generate "correct" results if the "correct result" was never specified?  What the hell do you need this for anyway?
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now