mbrinkley 0 Newbie Poster

Ok. Wow. I am dumbfounded with myself. Like I said before, I am a beginning programmer, therefore I am going to miss PLENTY of very small yet very significant errors/inconsistencies. At the command prompt I usually type just the name of the file without the extension: ex. "mydatamtb" instead of "mydatamtb.cpp". Thank you Jonsca and caut_baia for y'alls help. I am posting the finished code for you to enjoy.

#include <iomanip>
#include <iostream>
#include <string>

using namespace std;

//Prototypes
int ounces(float weight);
int days(int age);
int inches(int heightInches, int heightFeet);

//Main function
int main()
{
	//Variable declaration
	string name;
	string control;
	float age;
	float weight;
	float heightFeet;
	float heightInches;
	int newage;
	float newweight;
	int newheightInches;
	
		cout << "Type exit to exit the program." << endl;
		
		system("pause");
		system("cls");
		
		cout << "What is your first name?" << endl;
		cin >> name;
		
	while(name!="exit" || name!="Exit")
	{
		cout << "What is your age(in years)?" << endl;
		cin >> age;
		cout << "What is your weight(in pounds)?" << endl;
		cin >> weight;
		cout << "What is your height in feet and inches?" << endl;
		cout << "ex. 5 11" << endl;
		cin >> heightFeet >> heightInches;
//Call functions to calculate output and	
//Format output to display data
		newweight = ounces(weight);
		newage = days(age);
		newheightInches = inches(heightInches, heightFeet);
		
		cout << setw(30) << left << setfill('=') << '=' << endl;
		cout << name << " You are " << newage;
		cout << " days old." << endl;
		cout << "You weigh " << newweight;
		cout << …
mbrinkley 0 Newbie Poster

But I've never had to type ".exe" at the end of any of my program names to run them. What could have changed that would require me to type ".exe"?

mbrinkley 0 Newbie Poster

I'm using Borland Free Compiler so to compile I type "bcc32 mydatamtb.cpp" which is the name I have to call it for the professor. To actually execute the program afterward, where the trouble comes in, I type "mydatamtb.cpp".

mbrinkley 0 Newbie Poster

I think I might have finished my code. If anybody would be interested in compiling and running it for me, that would be great too. All help is appreciated. I'm just learning the foundations of programming right now.

mbrinkley 0 Newbie Poster

I have been given an assignment to plan, code, and execute a program to calculate data about a person. I am not here asking about how to code the program, but rather to troubleshoot at what's wrong with my compiler/command prompt. Here's what's happening: I will code a program in C++ using Crimson Editor as my text editor. With Windows XP, I use Borland Free Compiler to compile through the Command Prompt. After it compiles I execute(run) the program, but instead of printing the desired output to the command prompt screen, it opens a file with the .cpp code as the text. What is going on? I have no idea where to start and my finals programs are due by the end of the week. I am a second-semester freshman in college. All help or guidance is appreciated. Here is a sample program to use as a test:

#include <iostream>
#include <string>

using namespace std;

const int DAYS_PER_YEAR = 365;
const int OUNCES_PER_POUND = 16;
const int INCHES_PER_FOOT = 12;

int main ()

{
	string name;
	int age; int heightFeet; int heightInches;
	double weight;
	
	cout << "Please enter your first name, age, weight, and height in feet and inches, each separated by a space." << endl;
	cin >> name >> age >> weight;
	cin >> heightFeet >> heightInches;
	
	cout << endl << "Age in days = " << age * DAYS_PER_YEAR << endl;
	cout << "Weight in ounces = " << weight * OUNCES_PER_POUND << endl;
	cout << "Height …
mbrinkley 0 Newbie Poster

Why a linked list? What about just reading all the values into an array? Then you have everything you need right at your program-tips -- so to speak.

We have not yet started arrays. I believe after our test thursday we begin arrays, but this program is due thursday before the test. She, the professor that is, said it might be helpful to use temporary files, but I do not know anything about them. Do you have any suggestions with temporary files?

mbrinkley 0 Newbie Poster

Another quick question... Is there a way to use temporary files to hold the values to determine whether or not a value is greater than, less than, or equal to the average? If so, how do they work?

mbrinkley 0 Newbie Poster

Wow. I am dumbfounded. I completely forgot the fact that I would have to type the extension. The extension, by the way, is ".dat". Sorry for posting such a simple problem. I will post the final code when I am finished. Thank you both for input.

mbrinkley 0 Newbie Poster

Ok. I moved the line out of the while loop. But it is still doing the same thing. I added the code to check to see if the file is open and it doesn't display the message so I guess it's opening. The name of the data file that i'm trying to open is "List1". I type List1 in and the cursor moves to the next line and just blinks.... I do not know what to make of this. Any suggestions here?

mbrinkley 0 Newbie Poster

Hello. I am in a beginning C++ programming course in which we have just finished loops. I have been asked to plan, code, and execute a program to do the following things: Ask the user for the file name, then calculate an average of the numbers and display two lists of numbers, one of which will display the numbers less the average and the other displaying numbers greater than or equal to the average. The amount of numbers on the files is unknown. I have written the first part to input numbers from the file and to calculate an average but it does nothing and I can't figure out why. Any help whatsoever will be greatly appreciated.

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

ifstream inData;
ofstream outData;

int avgcounter = 0;
float number, sum = 0, average;
char filename[256];

int main()
{
	cout << "Please enter the name of the file." << endl;
	cin >> filename;
	
	inData.open(filename);
	
	while(!inData.eof())
	{
		inData >> number;
		
		sum = number + sum;
		average = sum / avgcounter;
		avgcounter++;
		
	}
	
	cout << "The average is " << average << '.';
	
	return 0;
}
mbrinkley 0 Newbie Poster

Galf,
Thank you for your input. Going through each line and explaining exactly what it did helped me to fix the code. The data file had the name and pay rate on two different lines. So, what I did, with the help from your response, was just omit the inData >> payto; line since the getline statement grabbed the first line and moved on. Thank you for both the responses. I'm sure I will have many more simplistic questions. I really do appreciate the help.

mbrinkley 0 Newbie Poster

Ok. Loops are actually what we are about to look at. Thank you for your direction to new material and assistance with this program.

mbrinkley 0 Newbie Poster

Myrtle Turtle,

Thank you for the reply. My class has not yet covered the "while" statement that you used. If you could explain what exactly it does and how it works, it would be appreciated. Thank you.

ALSO.....
I don't know if I explained the problem well. The program should read a name from the input file. Also, it reads an hourly pay rate that is used to calculate the total net pay. I have to display the dollars and cents separately as if it was written on a check. Sorry if there was any confusion. And thank you again for the response.

mbrinkley 0 Newbie Poster

I have been working on this program for about two weeks. I missed the day that the professor covered the material necessary to code this program due to surgery. I am now behind about 5 programs that are due at the end of the week and I'm trying to teach myself what I've missed. I have asked classmates for help and what they have told me has not been working. If anyone has the free time, I would absolutely love it if you could debug this program for me. I know this community is NOT for giving homework answers. I wrote all this code on my own and cannot figure out why if won't display the correct values in their respective places in the formatting. It is a program that we were assigned in a lab one day. The program is supposed to input a name and a pay rate from a data file, and then calculate the net pay and print it to an output file in a check format. The formatting is correct but the numbers are wrong. Please help.

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std; 

// Named constant definitions (and function declarations): 

ifstream inData;
ofstream outData;

// Main program: 

int main() 
{ 
// Variable declarations:
 
// Insert declarations from various parts below, as needed

float net;
float hrs;
float rate;
int dollars;
float cents; 
string payto;
string date;



// Function body: 

// Insert code from Part I algorithm - inputting data …
mbrinkley 0 Newbie Poster

Thank you both for your input on the problem. A friend and I looked over this problem together for about an hour last night and was able to get it executing properly. If you are wondering what the finished code looks like and what it does, I'm going to post the finished code as well. Once again, thank you both for assisting me with my question.

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

float minBal, balance, actNum, checking, saving;

char actType;

int main()
{
	cout << "What is your account number?" << endl;
	cin >> actNum;
	cout << endl;
	
	cout << "Is it a checking(C) or savings(S) account?" << endl;
	cout << "Press C for checking or S for savings (make sure to capitalize)." << endl;
	cin >> actType;
	cout << endl;
	
	cout << "What is your minimum balance?" << endl;
	cin >> minBal;
	cout << endl;
	
	cout << "What is your current balance?" << endl;
	cin >> balance;
	cout << endl;
	
checking = 25.00;
saving = 10.00;

	if (actType == 'C' || actType == 'c')
	{
		if (balance < minBal)
		{
			cout << "You have a service charge of $" << checking;
			cout << " for falling below your minimum balance of " << minBal << '.' << endl;
		}
	    {
		    if (minBal + 5000 >= balance)
			{
				cout << setw(15) << left << "Account Number" << setfill(' ');
				cout << setw(20) << right << "Type" << setfill(' ');
				cout << setw(20) << right << "Balance" …
mbrinkley 0 Newbie Poster

Hello. I am an IT major at Arkansas Tech University. I just began programming this semester. I have been given an assignment to give a bank customer certain information about their account and charges. So here is a shortened version of the question:

There are two types of accounts: Checking and Savings. Every customer must maintain a minimum balance. If a customer's balance falls below the minimum balance, there is a service charge of $10.00 for savings accounts and $25.00 for checking accounts. If the balance at the end of the month is at least the minimum balance, the account receives interest as follows:
A) savings accounts receive 4%.
B) checking accounts with balances of up to $5,000 more than the minimum balance receive 3% interest; otherwise, the interest is 5%.
Write a program that reads a customer's account number, account type, minimum balance that the account should maintain, and current balance. The program should output the account number, account type, current balance, and an appropriate message.

I know this is not a "do my homework" online community. I have worked on this program and cannot figure out what keeps happening. Any help will be appreciated. Thank you. I am new in this forum, but I guess I just post my code here:

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

float minBal, balance, actNum, checking, saving;

char actType;

int main()
{
	cout << "What is your account number?" << endl;
	cin >> …