OK, I looked for a noob section to the forum, but didn't find one. So here's my issue. I'm doing an exercise from a text book for a class I took two years ago. Back then, this wouldn't have been an issue. Now, having not looked at C++ for all of those two years, it's driving me nuts. I'm declaring a couple floats in my program, but when I output them, they get divided. How, I'm not sure. Truthfully, I have no idea what's going on. Here's the code.

#include <iostream>
#include <iomanip>
using namespace std;

void printbill(double kwhused, double rate, double charge, double tax, double total)
{
    // Print Logo
    cout << "pppppp   oooooo  w   w   w eeeeeeee rrrrrrr      cccccc   oooooo"       << endl;
    cout << "p     p o      o w   w   w e        r      r    c      c o      o"      << endl;
    cout << "p     p o      o w   w   w e        r      r    c        o      o"      << endl;
    cout << "pppppp  o      o w   w   w eeeeee   rrrrrrr     c        o      o"      << endl;
    cout << "p       o      o w   w   w e        r      r    c        o      o"      << endl;
    cout << "p       o      o w   w   w e        r      r    c        o      o..."   << endl;
    cout << "p       o      o  w w w w  e        r      r    c      c o      o..."   << endl;
    cout << "p        oooooo    w   w   eeeeeeee r      r     cccccc   oooooo ..."   << endl << endl;

    // Print column headers
    cout << setw(10) << "KW/H Used" << setw(10) << "Rate" << setw(10) << "Charge" << setw(10) << "Tax" << setw(10) << "Total";

    // Print data
    cout << setw(10) << kwhused << setw(10) << rate << setw(10) << charge << setw(10) << tax << setw(10) << total << endl << endl;
}

int main()
{
    // Declare constant variables(rate, taxrate)
    const double rate = .001;
    const double taxrate = .05;

    // Declare variables
    double charge, kwhused, total, tax;

    // Get kw/hr use
    cout << "Please input number of kilowatts used : " << endl << endl;
    cin >> kwhused;
    cout << endl << endl << endl;

    // Calculate charge
    charge = rate * kwhused;

    // Calculate tax
    tax = charge * taxrate;

    // Calculate total
    total = tax + charge;

    // Call the printbill() function
    printbill(kwhused, rate, charge, tax, total);

    return 0;
}

For my input, I enter 3000, it gets turned around and output as 0.15. The rate constant gets output as 3.15.

It has me confused.

Thanks for any help.

I don't get you problem, this is what I get for input of 3000.

pppppp   oooooo  w   w   w eeeeeeee rrrrrrr      cccccc   oooooo
p     p o      o w   w   w e        r      r    c      c o      o
p     p o      o w   w   w e        r      r    c        o      o
pppppp  o      o w   w   w eeeeee   rrrrrrr     c        o      o
p       o      o w   w   w e        r      r    c        o      o
p       o      o w   w   w e        r      r    c        o      o...
p       o      o  w w w w  e        r      r    c      c o      o...
p        oooooo    w   w   eeeeeeee r      r     cccccc   oooooo ...

 KW/H Used      Rate    Charge       Tax     Total
      3000     0.001         3      0.15      3.15

all I did was add a cout << endl; in line 23. Isn't that what you expected?

I don't get you problem, this is what I get for input of 3000.

pppppp   oooooo  w   w   w eeeeeeee rrrrrrr      cccccc   oooooo
p     p o      o w   w   w e        r      r    c      c o      o
p     p o      o w   w   w e        r      r    c        o      o
pppppp  o      o w   w   w eeeeee   rrrrrrr     c        o      o
p       o      o w   w   w e        r      r    c        o      o
p       o      o w   w   w e        r      r    c        o      o...
p       o      o  w w w w  e        r      r    c      c o      o...
p        oooooo    w   w   eeeeeeee r      r     cccccc   oooooo ...

 KW/H Used      Rate    Charge       Tax     Total
      3000     0.001         3      0.15      3.15

all I did was add a cout << endl; in line 23. Isn't that what you expected?

I missed the missing endl. Thanks. The issue was that the data line was printing immediately after the column headers, rather than under.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.