No, that is what is so weird about this. It seems like it is just that simple.

It is causing me to second guess myself. You know?

Oh, I know why the conditions are not being met, I just wanted to post this here in case I was missing something. Basically I want to ask if the function:


define STUFF

int My_Function(int, int);

void int(main){
... code here

int My_Function(int a, int b){
int c = 0;
if( a < b) c = b;
else if (b <= a) c = b;
else c = STUFF;
return c;


Can be rewritten as this function as maintain all of the logical flow:


int My_Function_Rewritten(int a, int b)

Sorry, allow me to clarify:

This code is meant to be stupid, and our task is to determine how stupid. We are supposed to determine what these functions do and rewrite them using better coding convention, removing unnecessary statements, etc.

So, this is the first of a series of questions and it seems asinine. The others were clever (a disguised and very convoluted memcpy, data structures, etc), but this one just seems too simple.

It seems like it is simply the assignment of c=a.

You're right; I did make a BIG mistake. The code should be:
[B]else if (b <= a) c = b; [/B]

Dear all,

I have a quick question about if-else-if control flow (you'd think by now these questions would be unnecessary, but here I am):

If I was told to rewrite a function that looked like this (this is an exam question so I am not asking the exact question in order to be within the honor code)


define STUFF

int My_Function(int, int);

void int(main){
... code here

int My_Function(int a, int b){
int c = 0;
if( a < b) c = b;
else if (b >= a) c = b;
else c = STUFF;
return c;

Issues with this code:

  1. No need for the definition
  2. No need for two arguments.
  3. The else condition is never reached.
  4. I could just replace with a one-line function return (input);

So, am I missing anything? Thanks for the help in advance!

Dear All,

I am running into issues integrating an image with content and automatically integrated background colors.

Currently my style sheet has the following definition:

[CODE]body {
background:#657491 url("") no-repeat top;
margin: 150px 10px 10px 10px;
font-family: verdana, arial, helvetica, sans-serif;
color: #657491;
font-size: 11px;

When I integrate my background image with the existing content everything plays nicely until I reach the end of the image, where I transition to color #657491, which works really well for the sides. I wanted some of the image to be transparent behind the content so I faded the background image itself, which works really well aesthetically.

The problem I have is, when the content exceeds the image I need another color to grow dynamically or else everything looks off.

Can anyone help me get this right? Here is my HTML:

[CODE]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- <style type="text/css">

</style> -->
<!--<link rel="stylesheet" href="style[2]bu.css" type="text/css" media="screen" />-->
<link rel="stylesheet" href="" type="text/css" media="screen" />
<table width="625" align="center" cellspacing="0" background-color="#FFFFFF" >
<td colspan="3"><table width="650" height="300" border="0px" align="center" cellspacing="0px" background-color="#FFFFFF" >
<!--<td colspan="3"><img src="" alt="Line" align="top" width=650 height=78></td>-->
<td width="10" valign="top" > </td>
<td width="450" valign="top" ><h2>Dear BIC Alumni,</h2>
<p>Summer greetings from the Baylor Interdisciplinary Core Office!* We are excited to announce a few changes and updates to the program in the last year: ...

Hello All,

I am trying to solve maximum flow, and I am experiencing some problems formatting the output.

Here is some pseudocode I am trying to implement.

c [u, v] is capacity from u to v, f [u, v] is the flow, cf [u, v] is the residual capacity.
for each edge (u, v) in the graph do:

f [u, v]: = 0; f [v, u]: = 0
cf [u, v]: = c [u, v], cf [v, u]: = c [v, u]
While there is a path p from s to t in residual flow graph do
r: = min (cf [u, v]: (u, v) is included in p)
for each edge (u, v) in p do
f [u, v]: = f [u, v] + r, f [v, u]: = - f [u, v]
cf [u, v]: = c [u, v] - f [u, v], cf [v, u]: = c [v, u] - f [v, u]


The first row contains an integer that specifies the number of vertices in V.
The second line consists of two integers s and t that defines the corners of source and outlet.
The third line consists of a number indicating | E |, ie the number of edges in the graph.
The following | E | rows consisting each of three integers corresponding to an edge.
The corners are numbered from 1 upwards. If you entered a corner of V we let V = {1, 2 ,..., a}. An edge is indicated by ...

Okay I figured out the default constructor. Now I need to create a function named "playerChoice" which changes the stored array value into whatever the player's space that is chosen and replaces it with an 'X' or 'O' and then calls a function to print out the current board status.

Hello, I am trying to declare a 2D array (3x3) inside of a class.

I have it set up like this:


include "GameBoard.h"
include <iostream>

using namespace std;

char board [3][3];

board [0][0] = 'a';
board [0][1] = 'b';
board [0][2] = 'c';
board [1][0] = 'd';
board [1][1] = 'e';
board [1][2] = 'f';
board [2][0] = 'g';
board [2][1] = 'h';
board [2][2] = 'i';

Game.cpp (Driver)

include "GameBoard.h"
include <iostream>

using namespace std;

int main()
cout << "Let's play Tic-Tac-Toe!!" << endl <<
"Player 1 gamepiece is X" << endl <<
"Player 2 gamepiece is O" << endl <<
endl << "Here's how the board is laid out" << endl << endl <<
"a|b|c" << endl << "-----" << endl <<
"d|e|f" << endl << "-----" << endl <<
"g|h|i" << endl << endl <<
"Let's begin..." << endl;

//cout << GameBoard.board[0][0]; // illegal
//cout << GameBoard::GameBoard.board[0][0]; //illegal

return 0;


ifndef GAME_H
define GAME_H
include <iostream>

using namespace std;

class GameBoard
char a,b,c,d,e,f,g,h,i;

    GameBoard(); // default constructor to set gameboard to all blanks. 
    /*playerChoice(char, char); // player's choice (X or O, location on brd)
    int isWin(); // displays a winner message
    printBoard(ostream &); // displays the current board to screen*/



What I am trying to do right now is be able to display my array using the class. I tried some of those but they were illegal declarations.

Okay, I figured out the destructor. Now I am having trouble with the "ostream & displayPoint (ostream &)" function.

Using "out" as the ostream variable, both "out << crud" and "return out" aren't working.

What should the destructor look like? Also, where should I go next with my code?

Hello everyone,

I am having some difficulty with a class assignment, partially because the professor has assigned it before we have covered the material. I have created a general case for the classes, but I really don't know what the assignment is asking me to do. Any help is appreciated, but I really need help figuring out where to go with this.

A couple specific questions:

  1. How do I create a destructor, and what does it do exactly (in terms of this program would be great)

  2. How do I get the data from the file to alter the class? I am having trouble with this and I KNOW this is a concept I will eventually have to master, so I am trying my best to get it right, but after trial and error I can't seem to get it. Any suggestions?

This is the assignment:

[I]Write a C++ class called point. You should create the following 3 separate files:
• Point.h: the header file for the point class;
• Point.cpp: the code and data for the point class; and
• PointDriver.cpp: a program to call and test your point class.

The PointDriver.cpp program should ask the user for the name of a data file. This data file will contain the coordinates for two points, one coordinate per line, in the order x, y, z. Your program should then declare two point objects. One point should be initialized by passing arguments for x, y and x. The second should ...

Basically what happens is I need the value to be updated. Essentially I have a mesh grid that fills in values from the bottom up (recursion). So in order to know the target value I must know the original values and then build it up.

So, I know my target value, it is given by the user, and I know the parameters of the equation. However, I don't know how to make a computer program that will make all values in between so the target value can be evaluated.

I need to make a loop that updates the loops by one step and uses the values generated and stored in tMplus and then checks that value to see if it the same grade as the t that I am asking for.

Well I figured the function wouldn't be necessary. I can just make one statement. Ignore that.

Sorry for late response.

Hello everyone, I am a Mathematics major and my mentor asked me to put together a program that evaluates explicit stencil methods along the difference mesh. Basically I need to use a recursive method to get my value, as I know base values and boundaries, but the C++ experience I have is minimal, and I need to use iterated loops. I am having trouble, and if anyone can help I would appreciate it.

This is the wiki page for Explicit stencil: (Note I am not using standard central difference)


Here is my code thus far:

This program will take in a lower level node on the finite-difference mesh and
output a node that is on the level above it. This program also takes in a value
for lambda for future use. This program takes in a value for the stepsize along
the x axis.


include <iostream>
include <cmath>

using namespace std;
//long double forwardAdjustedCentral(long double, long double);

int main()
long double uN, n, x, t, lambda, tau, h, H, Hminus, uNminus, uNplus, tMplus;

cout << "Enter a negative value for lambda: ";
cin >> lambda;
cout << "Enter a value for a stepsize tau on the t axis: ";
cin >> tau;
cout << "Enter a value for a stepsize h on the x axis: ";
cin >> H; 
cout << "Enter a node on the finite difference mesh (x,t): ";

cin >> x;
cin >> t; 

Hminus = H;

//long double array oldu ...

Hello everyone,

I am trying to get a head start on this week's program, as it seems to be a long, albeit relatively easy, program. I wanted to double check with the experts here to make sure the flow of control for this program is correct. The assignment is as follows:

The ability to write functions is one of the more powerful capabilities in C++. Functions allow code to be reused, and provides a mechanism for introducing the concept of modularity to the programming process. In addition to the concept of functions, C++ allows complex programs to be organized using header files (.h files) that contain the prototypes of functions and implementation files that (.cpp files) that contain the implementation (definition) of the functions.

            In this programming assignment you will be asked to implement a number of useful functions using a header file and an implementation file.  You will place the prototypes for your function in a .h file, and implement these functions in a .cpp file.  You will need to write a driver (a program designed to test programs) to test your functions before you upload them.


* MyFunctions.h

* MyFunctions.cpp

* Driver.cpp


  1. maximum

     1. Precondition
                                                           i.      two integer values exist
     2. Postcondition
                                                           i.      The value of the largest integer is returned.
                                                          ii.      The original integers are unchanged
                                                        iii.      If the integers have the same value then the value of either integer is returned.
     3. Return
                                                           i.      integer
     4. Description
                                                           i.      Function returns the value ...

What would a flowchart look for this?

Hmm... I'm trying to figure out who that post was intended for.

What would a flowchart for this program look like?

Here is what helped me if anyone else is having this same problem:

[CODE]while (infile2 >> num)

        if (count3 == 0) 
            max = num;
            min = num;
        if (num > max) 
            max = num;
        if (num < min)
            min = num;

        sum += num;
        totSum += num;

I have tried a variety of methods, but can't get the loop to store a max number. Can someone help?

[CODE]while (infile >> lastName && infile >> firstName && infile >> mInitial)

    revName = firstName+lastName+ext;;
    if (!infile2)
        cout << "Error opening file. \n";
        return 1;
    while (infile2 >> num)

        if( num > num)
            max = num;

        sum += num;
        totSum += num;
    avg = sum/count1;
    cout << firstName << " " << mInitial << " " << lastName << ":\t" << fixed 
         << setprecision(2) << avg <<endl;
    count1 = 0;
    num = 0;
    sum = 0;

I was thinking I should do it along those lines. In order to do this do I need to check every value that I read in? Should I compare every new value with the one stored at min and max?


Alright everyone,

The program I currently have running has a while-loop with an embedded while-loop. I now need to calculate the max and min, but the only way I can come up with to do so is using conditional statements where I take the values I know and compare them. I don't know how to use arrays, so I don't think I can use them. We are just learning loops right now. If anyone has any suggestions, I would appreciate them.

Thank you, that is extremely helpful. I am going to put together some code and then post back what I come up with. Thanks again.

Hello everyone,

I am having a really difficult time getting this program off of the ground. I need to use a while loop to read data from a file and then read tonnage numbers corresponding to names read in from that file. The assignment looks something like this:

[I]After watching the Discovery Channel’s, Ice Road Truckers, German transportation tycoon Otto Bonn is expanding his business to North America. He has been taking resumes from truck drivers through out the U.S. and Canada. He has collected a large number of files that contain the per season tonnage transported for several drivers, and he is asking you to write a C++ program that will ask the user for the name of a data file. This data file contains a list of drivers. The names are listed, one per line, in the following format:

lastName firstName middleInitial

and each part of the name is separated by a space.

Each driver has a data file that contains an unknown number of seasons. The name of each driver’s data file is formed by concatenating the drivers first and last name and adding “.dat”, for example:

Driver Name: Nowak Alex D

Driver Data File: AlexNowak.dat

Your program should open each driver’s data file, read in the tonnage and calculate the driver’s average tonnage per season. In addition to calculating the average tonnage for each driver you should report the average for all drivers, and the highest and lowest tonnage.

Note: All tonnage averages should be rounded ...

Hey, yeah that was the coding error I was talking about. I fixed it and it seems to be working, I am going to record the problem as solved. Thanks a bunch.

  • rep

Oops. I ****ed it on that last section of code. Now it seems to be working and this is my final code: I am going to look it over a little before I submit it for good.

[CODE]#include <iostream>

include <fstream>
include <string>

using namespace std;

int main ()
int num1, num2, num3, num4, num5, num6, num, menu;
string name1, name2, name3, name4, name5, name6, name;
ifstream infile;"colors.txt");

infile >> num1;
getline(infile, name1); 

infile >> num2;
getline(infile, name2); 

infile >> num3;
getline(infile, name3);

infile >> num4;
getline(infile, name4);

infile >> num5;
getline(infile, name5);

infile >> num6;
getline(infile, name6);


cout << "1. Number" << endl;
cout << "2. Name" << endl; 
cin >> menu;

if (menu == 1)
    cout << "What is the number?" << endl;
    cin >> num;

    if (num == num1)
        cout << "The color is: " << name1 << endl;

    else if (num == num2)
        cout << "The color is: " << name2 << endl;

    else if (num == num3)
        cout << "The color is: " << name3 << endl;

    else if (num == num4)
        cout << "The color is: " << name4 << endl;

    else if (num == num5)
        cout << "The color is: " << name5 << endl;

    else if (num == num6)
        cout << "The color is: " << name6 << endl;

        cout << "Can't find that color. Goodbye!" << endl; ...



I'll try that in a few minutes, but I think this is more along the lines of what my professor wanted us to do.


Thanks for the thought, but our class has not progressed that far yet.

I could do so in this manner, but I am trying to learn to master the methods we are learning at the moment rather than branching out to different, more efficient ways to code. If I use conditional statements, then do I need the return 0; statement?