what i've here it's part of a program, i just want want someone to tell me what command i can used with Setprecision and setw to input a name and display the date;
when i try the command below, he just make the report unwritable
cout << "Person name: " <<setw(4) << Person name << endl;
yes the code compile, but when i plug in this line: cout << "Person name: " <<setw(4) << Person name << endl; to input the person name, the compiler give me garbage
Are you expecting << Person name << to prompt the user to input the person's name or are you expecting it to output the person's name? Either way, read http://www.cplusplus.com/doc/tutorial/basic_io/
the prompt should be like: "enter the person name"; i can have the prompt to come but it wont let the remaining part of the report appear which are:
cout << "Sales: $" <<setw(8) << Sales << endl;
cout << "Cost: $" <<setw(8) << Cost << endl;
cout << "Gain : $" <<setw(8) << Gain << endl;
that's why i was wondering if there's a command setw who can let set the name
i've this program below, and i'm not able to set up the program to asked for the sales person name using:
cout << "\nEnter the sales Person name: ";
cin >> salesPerson;while
i'm also using the setprecision manipulator to print the report. can someone review this and let me know what i'm missing. without the name problem the program is working fine.
Thanks,
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double TotalSales,
CostSales,
NetProfit;
int salesPerson;
cout << "\nEnter the sales Person name: ";
cin >> salesPerson;
cout << "\nEnter the Total Sales: ";
cin >> TotalSales;
cout << "\nEnter the cost Sales: ";
cin >> CostSales
that's correct, but when the user enter a name the following lines are just garbage, but when i take the salesPerson out the program works fine. I guess my problem is to have the lines appears normaly with the salesPerson
im not sure if it makes a difference or not but try setting fixed before setprecision. setprecision acts differently based on the flag of the ostream..
cout << fixed << setprecision(2);
what does your output look like?
oh, you are missing a ';' after cin >> CostSales
also you need to initialize netprofit or else c++ will make it a garbage number when you try to output it.