a program that prints input in different positions.

Write a program that asks a user to enter his/her first name, last name and the marks of three tests (out of a 100), and then the program prints to the screen the user’s first name (in the first 15 positions), last name (in the next 15 positions), and the average formatted with two decimal digits.

Can anybody please help me fix my code? and, how do I format my program to print two decimal places?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main()
{
string first_name, last_name;
double avg;
int mark1, mark2, mark3;

cout<<"Enter your first & last names, and the marks of 3 of your tests: ";
cin>> first_name>>last_name>>mark1>>mark2>>mark3;

avg= (mark1+mark2+mark3)/3.0;

cout<<setw(15)<<first_name<<endl;
cout<<setw(30)<<last_name<<"\n"<<avg<<endl;


    return 0;
}
Last edited on
closed account (SECMoG1T)
http://www.cplusplus.com/reference/iomanip/setprecision/
http://www.cplusplus.com/reference/iomanip/setw/
Topic archived. No new replies allowed.