hi for this where would i put printf("
For %d minutes: your bill is $%.2f

#include <iostream>
#include <cctype>
#include <iomanip>
#include <cstdlib>

using namespace std;

void SetPrecision (int);

int main (void)
/*local data space */
double rate;
double hours;
double grosspay;
char go;

/*begin procedual code */
cout << "This program calculates the grosspay.

     /* get the input data from the keyboard */
     cout << " Enter the Rate: ";
     cin >> rate;
     cout << " Enter the hours worked: ";
     cin >> hours;
     /* calculate the gross pay */
     grosspay = rate * hours;
     /*display the output */
     cout << " The gross pay is: " << grosspay << "

     /* ask the user if he/she wants to continue */
         cout << "
Calculate another?(Y or N)" ;
         cin >> go;
         while (toupper(go) != 'Y' && toupper(go) != 'N');
         } while (toupper(go) == 'Y');
         cout << endl;
         void SetPrecision(int pDecPlaces)

> where would i put printf

You do not need printf at all as you are using the C++ stream library
The format flags ios::right, ios::fixed, ios::showpoint and setting the precision give equivalent functionality to "%.2f" in printf. Incidentally, you need to do this only once - the flags and precision once set stay in affect for all subsequent output operations.

You need to include the header <cctype> for std::toupper.

system("pause") represents a vulnerability (an unsafe programming practice) which can be exploited by an attacker. A malicious attacker could replace the "pause" program on the machine with a program that does some kind of damage, and use it to cause trouble. Spoofing a legitimate and harmless program is a common practice among malware. This should be avoided in real-life production code and it is best not to get into the habit of using this construct.

In addition, it also has the drawback that the argument string is not portable across different implementations. Your code may work on windows, but may do something completely different (or not work at all) on unix.

A portable and less risky way to wait for the user to enter a new line is:

 std::cin >> std::ws ; // throw away white spaces remaining in the input buffer
 std::cin.get() ; // wait for the user to enter a new line  


All Answers

Answers by Expert:

Ask Experts




my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.


about 15 years or so

post graduate engineer

©2016 About.com. All rights reserved.