Question: Write a c++ program that Prompts the user to enter the following information. - Name (First and Last entered together separated by a space) -

Write a c++ program that

  1. Prompts the user to enter the following information.

- Name (First and Last entered together separated by a space)

- Age

- Address (Handle spaces)

- Salary

  1. Display (on one line) the information entered with format given below.

(Notice that the order is different than how the data was entered)

- Name (left justified in a field of 20)

- Address (left justified in a field of 20)

- Age (right justified in a field of 5)

- Salary (right justified in a field of 10, fixed, precision 2)

Example output (the dashes represent spaces to see them more clearly):

Fred Smith----------123 Main St.-----------43--67500.00

#include

#include

using namespace std;

int main()

{

char name[20];

int age;

char address[20];

float salary;

cout<<"enter name: ";

cin>>name;

cout<<"enter age: ";

cin>>age;

cout<<"enter address: ";

cin>>address;

cout<<"enter salary: ";

cin>>salary;

std::cout.width(20); std::cout << std::left << name;

std::cout.width(20); std::cout << std::left << address;

std::cout.width(5); std::cout << std::right << age;

std::cout.width(10); std::cout << std::right <

return 0;

}

This code does not come out with right output help me thanks.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!