I have NO clue what i am doing in C++ because i learned java. the program has to put out a file in the following format:
Community Hospital Billing Statement
Number of days spent in hospital: XX
Type of room: {Private, Semi-Private, Ward} << based on input
Room Charge: {room price x number of days) << rm * d
Telephone Charge: {tp * d}
Television Charge: {vp * d}
Total Due: {(rm*d)+(tp*d)+(vp*d)
#include <iostream>
#include <fstream>
#include <stdio.h>
usingnamespace std;
int main()
{int d, rp, tp, vp, t, rm, ts, tv;
ofstream bill;
bill.open("bill.txt");
{
cout << "This program is used to create a bill statement \n";
}
{
cout << "How many days did the patient stay? ";
cin >> d;
}
{
cout << "\nWhat type of room? \nP for private, S for semi-private, W for ward: ";
cin >> rm;
if ( rm == 'P' || rm == 'p' ) rp = 200;
if ( rm == 'S' || rm == 's' ) rp = 150;
else (rp = 100);
}
{
int ts;
cout << "\nWas there telephone service? Y for yes, N for No: ";
cin >> ts;
if( ts == 'Y' || ts == 'y' ) tp = 1.75;
else(tp = 0);
}
{
cout << "\nWas there television service? Y for yes, N for No: ";
cin >> tv;
if( tv == 'Y' || tv == 'y' ) vp = 1.75;
else(vp = 0);
}
{
t = (vp*d)+(tp*d)+(rp*vp);
cout << "\nThe total bill is: " << t;
}
}
so the last line of that would work as just if ( rm == 'W' || rm == 'w' ) rp = 100;
Then the other thing is, it builds and runs no error , but after the second input of one of the 3 letters, it just stops working right. It will spit out the text of the next 3 cout lines without input and does not spit out a total.
And i also do not know how to make it generate the text file.
#include <iostream>
#include <fstream>
#include <stdio.h>
usingnamespace std;
int main()
{int d, rp, tp, vp, t, rm, ts, r, tv, rc, tc, vc;
ofstream bill;
bill.open("bill.txt");
{
cout << "This program is used to create a bill statement \n";
}
bill << "Community Hospital Patient Billing Statement\n";
{
cout << "How many days did the patient stay? ";
cin >> d;
}
bill << "Number of days stayed: " << d << "\n";
{
cout << "\nWhat type of room? \nP for private, S for semi-private, W for ward: ";
cin >> rm;
if ( rm == 'P' || rm == 'p' ) rp = 200;
if ( rm == 'S' || rm == 's' ) rp = 150;
if ( rm == 'W' || rm == 'w' ) rp = 100;
}
{
bill << "Type of room: ";
if ( rm == 'P' || rm == 'p' ) r = "Private";
if ( rm == 'S' || rm == 's' ) r = "Semi-Private";
if ( rm == 'W' || rm == 'w' ) r = "Ward";
bill << r << "\n";
}
rc = rp * d;
bill << "Room Charge: " << rc << "\n";
{
cout << "\nWas there telephone service? Y for yes, N for No: ";
cin >> ts;
if( ts == 'Y' || ts == 'y' ) tp = 1.75;
else(tp = 0);
}
tc = tp * d;
bill << "Telephone charge: " << tc << "\n";
{
cout << "\nWas there television service? Y for yes, N for No: ";
cin >> tv;
if( tv == 'Y' || tv == 'y' ) vp = 1.75;
else(vp = 0);
}
bill << "Television Charge: " << vc << "\n";
{
t = vc + tc + rc;
//tv prive times days + telephone times days + room cost times days
cout << "\nThe total bill is: " << t;
}
bill << "Total Due: " << t << "/n";
bill.close();
}
#include <iostream>
#include <fstream>
#include <stdio.h>
usingnamespace std;
int main()
{int d, rp, tp, vp, t, rc, tc, vc;
char rm, ts, tv;
constchar* r;
ofstream bill;
bill.open("bill.txt");
{
cout << "This program is used to create a bill statement \n";
}
bill << "Community Hospital Patient Billing Statement\n";
{
cout << "How many days did the patient stay? ";
cin >> d;
}
bill << "Number of days stayed: " << d << "\n";
{
cout << "\nWhat type of room? \nP for private, S for semi-private, W for ward: ";
cin >> rm;
if ( rm == 'P' || rm == 'p' ) rp = 200;
if ( rm == 'S' || rm == 's' ) rp = 150;
if ( rm == 'W' || rm == 'w' ) rp = 100;
}
{
bill << "Type of room: ";
if ( rm == 'P' || rm == 'p' ) r = "Private";
if ( rm == 'S' || rm == 's' ) r = "Semi-Private";
if ( rm == 'W' || rm == 'w' ) r = "Ward";
bill << r << "\n";
}
rc = rp * d;
bill << "Room Charge: " << rc << "\n";
{
cout << "\nWas there telephone service? Y for yes, N for No: ";
cin >> ts;
if( ts == 'Y' || ts == 'y' ) tp = 1.75;
else(tp = 0);
}
tc = tp * d;
bill << "Telephone charge: " << tc << "\n";
{
cout << "\nWas there television service? Y for yes, N for No: ";
cin >> tv;
if( tv == 'Y' || tv == 'y' ) vp = 1.75;
else(vp = 0);
}
vc = vp * d;
bill << "Television Charge: " << vc << "\n";
{
t = vc + tc + rc;
//tv prive times days + telephone times days + room cost times days
cout << "\nThe total bill is: " << t;
}
bill << "Total Due: $" << t << "\n";
bill.close();
}
cout << "\nWhat type of room? \nP for private, S for semi-private, W for ward: ";
cin >> rm;
rm = std::toupper(rm)
if ( rm == 'P' ) rp = 200;
if ( rm == 'S' ) rp = 150;
if ( rm == 'W') rp = 100;
I still don't see why you have braces around everything.
Yes, but shouldn't you strive to be better? It might work, but doesn't mean it is good. If you have these habits now for this small program, what is it going to be like when you do a much bigger program? There is strong potential for it to be a big mess.
i tried double and float, but i only get whole numbers
Ok, so what was the input, and what did the output look like?
My other advice about using the std::toupper is independent of the language you program in - I imagine it is still reasonable advice whether you use Java, PASCAL, C, Python, FORTRAN or whatever.
Going back to my first post, C++ isn't my thing... after this, i'm going back to java.
So, Java uses bunch of unnecessary braces? I don't think so.
Lines 13, 15, 17, 20, 22, 29, 30, 36, 39, 45, 48, 54, 57 and 61 are all unnecessary and just clutter up your code and make it hard to read. This style would be hard to read in Java, too.
Number of days in hospital : 5-------------- d = 5
Type of room : Private------------------------ rp = 200
Room Charge $ 1000.00--------------------- d * rp = rc ---- RC = 1000
Telephone Charge $ 0.00------------------- d * tp = tc ----- TC = 0
Television Charge $ 17.50------------------- d * vp = vc ---- VC = 17.50
Total Due $ 1017.50 -------------------------- rc + tc + vc = t -- 1017.50
the program only gives the total as 1017
it is ignoring decimal numbers.
text doc output:
Community Hospital Patient Billing Statement
Number of days stayed: 5
Type of room: Private
Room Charge: 1000
Telephone charge:
Television Charge: {random character}
Total Due: $1017
tc is a char, but you're using it to store a number. When you output tc to file, because it is a char and not a number, you get out a char - not a number.
This is why we don't give variables ridiculous short names like tc. If you had named your variables sensibly, and called it something like "telephoneCharge", you would have spotted instantly that making it a char was silly.
Do not use ridiculous short names like tc for your variables. You are making it harder for yourself.