Clinton Portis 211 Practically a Posting Shark

The easiest way to read diagonally through your array would be to take the procedural approach and just write out each element of the 2d array that makes up the diagonal you want to add.

But it seems like you are looking for a better method that would involve less code, using a loop. When it comes to something like this, look for a pattern. Once you've discovered the pattern, you have to make it part of your loop condition.

For example, in your [10][10] array, you start out at [0][0], then [1][1], then [2][2], then [3][3] and so on.. so we have identified a pattern; from [0][0], each subsequent element of the diagonal is [row+1][col+1]. So we can make this part of our loop condition:

int subtotal = 0;

//one diagonal
for(int i=0, i<10, i++)
{
     //increment diagonally through the array
     subtotal += array[i][i];
}

To get the other diagonal, you would start at [0][10], then go to [1][9], then [2][8], then [3][7].. etc. Initialize the element indicies to 0 and 10 and handle them appropriately in your loop condition in such a manner that will result in a diagonal summation.

Clinton Portis 211 Practically a Posting Shark

try 1-800-admin

Clinton Portis 211 Practically a Posting Shark

in your function, try the following at #17:

string temp1, temp2;

while(getline(fin, temp1))
{
     //Handle even number of lines
     if(getline(fin, temp2))
     {
          fout << temp2 << endl;
          fout << temp1 << endl;
     }
     //Handle odd number of lines
     else
     {
          fout << temp1;
     {
}
Clinton Portis 211 Practically a Posting Shark

Your request is very vague. I actually still have no clue what you are asking for. If I had to guess, you require a bar graph that will display in percent a user entry vs. proper zip-code format. For example, if a user enters 48$43-0020, 8 out of 9 characters qualify as a correct zip code format, which is 89%. A resulting bar graph could look like this:

0 10 20 30 40 50 60 70 80 90 100
**********************************


If this even close to what you are asking for, no one knows except for you. Please, enlighten us; unlock the mystery that is your c++ problem.

Clinton Portis 211 Practically a Posting Shark

You will have to write the spaces between the numbers:

catOut << stuff << ' ' << more_stuff << ' ' << endl;
Clinton Portis 211 Practically a Posting Shark

1. When reading in your pgm file, I would recommend reading it into 2D array:

int pixels[256][256];

2. You could read in the pgm file like this:

//Get file type
catIn >> type;
//Get file dimensions
catIn >> length >> width;
//Get grayscale max value 
catIn >> grayscale_max;
//Get pixels
for(int i=0; i<256; i++)
{
     for(int j=0; j<256; j++)
     {
          catIn >> pixels[i][j];
     }
}

3. Now that you have a nicely packaged pgm file.. all you need is that almighty emboss function:

void emboss(int& pixels[][])
{
     int result = 0;

     //I am using loop conditions that will start the emboss operation at the lower-right non-border pixel 
     //and work backwards through the pgm file

     //backwards row traversal
     for(int i=254; i>0; i--)
     {     
          //backwards column traversal
          for(int j=254; j>0; j--)
          {
               //Perform 'emboss math'
               result = (pixel[i+1][j+1] - pixel[i][j]) + 8;
               
               if(result < 0)
               {
                    result = 0;
               }
               else if(result > 15)
               {
                    result = 15;
               }

               //Assign the new 'emboss' value 
               pixel[i][j] = result;   
          }
     }
}

4. All there is left to do now is to use your catOut object to open a new file and write the pgm file header info and pixels[][] to file. It will conveniently look similar (yet opposite) to step #2.

All of this code is untested. It is just an idea of how I'd probably go about doing this. There are probably many many ways to get this done. If anyone see's a better way to do this …

Clinton Portis 211 Practically a Posting Shark

Very good then.. I was considering that where you start the emboss operation makes a difference as it affects pixels progressivley through the pgm file (starting at the upper-left corner would have a different effect than starting at the lower-right corner for example)

Having a fixed 256 256 file size is kinda cool, although it would be simple to account for pgm files of any size.

Give me a chance to grab a beer or 2 and I'll knock out some pseudo code for ye'.

Clinton Portis 211 Practically a Posting Shark

I am still a little unclear on how to perform an 'emboss' operation.. I'd hate to give you wrong code based on my misunderstanding.

From what I understand, we first identify a (non-border) pixel to emboss. In this case, we'll attempt modify the "15" pixel:

P2
4 4
15
0  0   0  0
0 [b]15[/b]  10  0
0  7   5  0
0  0   0  0

Then we identify the pixel located to the 'lower-right', which in this case is the "5" pixel (which can be a border pixel):

P2
4 4
15
0  0   0  0
0 [b]15[/b]  10  0
0  7   [b]5[/b]  0
0  0   0  0

In this example, according to your emboss forumla, we have (5 - 15) + 8 = -2 which is < 0. Therefore, the 15 pixel when embossed becomes 0.

This is my understanding of the emboss operation thus far.. am I close?
(Doesn't make sense to me.. turning a white pixel to black)

-dw

Clinton Portis 211 Practically a Posting Shark

1. you never initilize the 'count' variable.. it could be anything. (you should also do the same for 'average' as good practice)

2. you should decrement the count variable by 1 before using it in calculations in order to account for an extra loop iteration in the case of a -1 entry.

3. you should move line #14 outside of the loop.

Clinton Portis 211 Practically a Posting Shark

Hello Ms. Christina,

Let me first say that I have never done any work with .pgm files. I've just looked at some .pgm examples though, and it doesn't look too terribly difficult. However, I think we might have to put our brains together to come up with the result that ye' be looking for.

With that said, I am unclear when it comes to "subtracting the lower right and subtracts the center pixel." If you can provide me a notepad example of a .pgm file, and show me what it means to perform the subtraction, I am sure I can help you on the file I/O, array and pixel manipulation.

-Dave W.

ChristinaS commented: Fab! Thx! +2
Clinton Portis 211 Practically a Posting Shark

I just threw some code your way to get you started.. maybe jog some of them brain cells. I purposely did not finish your assignment.

This was my thought process (although somewhat impaired after just comming back from a fresh concert last night featuring Axe Murder Boyz opening up for ABK):

1. create a counter that will hold student's test performance based on 5 test ranges: 0-29, 30-49, 50-69, 70-89, and 90-100. Each second-dimension element will serve as a 'counter' of how many test results qualified for each range:

//First  Dimension: [0] is the assignment, [1] is lab, [2] is test, and [3] is exam
//Second Dimension: [0] is 0-29, [1] is 30-49, [2] is 50-69, [3] is 70-89 and [4] is 90 to 100

int ranges[4][5];  

//to make our array easier to read, i'll also do the following quick little trick:
//assign = 0, lab = 1, test = 2, and exam = 3

enum{assign, lab, test, exam};

2. Now that I got a counter, I needed a function that I could plug in test information and will return which element of ranges[][] to populate:

int get_range(int& grade)
{
     if(grade < 30)
     {
          //increment ranges[][0]
          return 0;    
     }
     else if(grade >= 30 && grade <= 49)
     {
          //increment ranges[][1]
          return 1;
     }
     else if(grade >= 50 && grade <= 69)
     {
          //increment ranges[][2]
          return 2;
     }
     else if(grade >= 70 && grade <= 89)
     {
          //increment ranges[][3]
          return 3;
     }
     else
     {
           //Anything else must …
Clinton Portis 211 Practically a Posting Shark

Administrator locked out my edit:

I will be decisive and assume that you need the number of A's, B's, C's, D's, and F's for the assignment, lab, test, and exam. A's will be 100% to 90%, B's, will be 89% to 80%, C's will be 79% to 70%, D's will be 69% to 60%. F's will be below 60%:

int get_grade(int& grade, char& test)
{    
     //test: A = assignment, L = lab, T = test, E = exam

     grade /= 10;

     switch(grade)
     {
          case 10:
          case  9:  return 0;     break;
          case  8:  return 1;     break;
          case  7:  return 2;     break;
          case  6:  return 3;     break;
          default:  return 4;     break;
     }
}

int grades[5];  // A's = [0], B's = [1], C's = [2], D's = [3], F's = [4]

 inFile    >>stumarks[i].studentid >>stumarks[i].seperator>>stumarks[i].progassn
           >>stumarks[i].seperator>>stumarks[i].lab
           >>stumarks[i].seperator
           >>stumarks[i].test>>stumarks[i].seperator
           >>stumarks[i].exam;

//Populate grade statistics
grades[get_grade(stumarks[i].progassn, A)]++;
grades[get_grade(stumarks[i].lab,  L)]++;
grades[get_grade(stumarks[i].test, T)]++;
grades[get_grade(stumarks[i].exam, E)]++;
Clinton Portis 211 Practically a Posting Shark

I will be decisive and assume that you need the number of A's, B's, C's, D's, and F's for the assignment, lab, test, and exam. A's will be 100% to 90%, B's, will be 89% to 80%, C's will be 79% to 70%, D's will be 69% to 60%. F's will be below 60%:

int get_grade(studmarks& s, char& test)
{
     //test: A = assignment, L = lab, T = test, E = exam

     int grade = 0;

     switch(test)
     {
          case 'A':  grade = s.progassn / 10;  break;
          case 'L':  grade = s.lab  / 10;      break;
          case 'T':  grade = s.test / 10;      break;
          case 'E':  grade = s.exam / 10;      break;
     }

     switch(grade)
     {
          case 10:
          case  9:  return 0;     break;
          case  8:  return 1;     break;
          case  7:  return 2;     break;
          case  6:  return 3;     break;
          default:  return 4;     break;
     }
}

int grades[5];  // A's = [0], B's = [1], C's = [2], D's = [3], F's = [4]

 inFile    >>stumarks[i].studentid >>stumarks[i].seperator>>stumarks[i].progassn
           >>stumarks[i].seperator>>stumarks[i].lab
           >>stumarks[i].seperator
           >>stumarks[i].test>>stumarks[i].seperator
           >>stumarks[i].exam;

//Populate grade statistics
grades[get_grade(stumarks[i].progassn, A)]++;
grades[get_grade(stumarks[i].lab,  L)]++;
grades[get_grade(stumarks[i].test, T)]++;
grades[get_grade(stumarks[i].exam, E)]++;
Clinton Portis 211 Practically a Posting Shark

When you say you need the "range of marks", are you asking for the the highest and lowest score for each exam?

Clinton Portis 211 Practically a Posting Shark

you might have to #include<string>

Clinton Portis 211 Practically a Posting Shark
string stuff[10];

stuff[2] = "infinity";

for(int i=0; i<10; i++)
{
     cout << stuff[i] << endl;
}
Clinton Portis 211 Practically a Posting Shark

Ah, that makes sense. Adjust the code to account for the given day.

I would recommend dedicating a variable that will identify a call as either weekday or weekend. I would probably make this a bool type variable. For this example, I'll call make it bool is_weekend, set to false if it is a weekday call and set to true if it is a weekend call:

//all calls will be at least E1.50
full_cost = 1.5;

//adjust call duration
if(call_duration > 3)
{
     call_duration -= 3;  //3 minutes
}

//enforce 10hr. limit
if(call_duration > 597)
{
     call_duration = 597;  //10hr. limit (minus 3min. initial charge) converted to minutes
}

//identify call as a weekday or weekend call
if(chday == 'A' || chday == 'S')
{
     is_weekend = true;
}
else
{
     is_weekend = false;
}

//make rate determinations (calls made between 11pm to 8am ending before 5pm)
if(call_start >= 2300 && call_start <= 0800 && call_end <= 1659)
{
     //weekday call
     if(!is_weekend)
     {
          //calculate reg. rate and apply 40% discount
          full_cost += (call_duration * .30) * .6;
     }
     //weekend call
     else
     {
          //calculate reg. rate and apply 60% discount
          full_cost += (call_duration * .30) * .4;
     }    
}

So on and so forth.

Clinton Portis 211 Practically a Posting Shark

Although I don't fully understand the assignment, I will attempt to throw some code your way to help get the gears spinnin' inside ye' head.

based on your current coding style, i would suggest simple if/else logic:

//all calls will be at least E1.50
full_cost = 1.5;

//adjust call duration
if(call_duration > 3)
{
     call_duration -= 3;  //3 minutes
}

//enforce 10hr. limit
if(call_duration > 597)
{
     call_duration = 597;  //10hr. limit (minus 3min. initial charge) converted to minutes
}

//make rate determinations (calls made between 11pm to 8am ending before 5pm)
if(call_start >= 2300 && call_start <= 0800 && call_end <= 1659)
{
     //calculate reg. rate and apply 40% discount
     full_cost += (call_duration * .30) * .6;
}

//for calls made before 8am lasting longer than 5pm
else if(call_start >= 2300 && call_start <= 0800 && call_end <= 2259)
{
     //calculate reg. rate, apply 40% up until 5pm
     full_cost += ((1659 - call_start) * .30) * .6;
     //then apply 60% discount after 5pm
     full_cost += ((1700 + call_end) * .30) * .4;
}

/* 
     and so on and so forth, accounting for all the different call scenarios, but not accounting for calls that exceed 10 hours.
*/

This is not complete code but it is at least something to get you started.


This does not make sense to me, because it says you apply a discount, but then it says to apply another discount.. quite confusing:

Before 8am 40% discount 60% discount
8am …

Clinton Portis 211 Practically a Posting Shark

Force total user compliance: (you call it error trapping)

do{

     //stuff
     //suff
     //and more stuff

     if(is user input correct?)
     {
          //Display error message
     }

}while(user input is incorrect);

To run your program multiple times, do this:

int main()
{
     char choice = '\0';

     do{
  
          //stuff
          //stuff
          //stuff

          cout << "\nWould ye' like to try again?  (Y/N): ";
          cin >> choice;

     }while(choice == 'y' || choice == 'Y');
 
     return 0;
}

Follow these simple topologies and ye' will be good to go.

jonsca commented: Mad rep for using the word "topology" in your post +2
Clinton Portis 211 Practically a Posting Shark

Your plus is almost done.. except you need to move the top 1/2 veritcal line and the bottom 1/2 vertical line off the left edge of the screen.

One way you can get the spaces you need, is to create an array of spaces:

int size = 0;

//Declare the array 
char spaces[80];

//Initialize the array to all spaces
for(int i=0; i<80; i++)
{
     spaces[i] = ' ';
}

cout << "Enter size of plus sign: ";
cin >> size;

//Put a null terminating delimiter in the space array so we will have the correct amount of padding
spaces[size/2] = '\0';

//Now you have a set number of spaces to use to pad your plus sign :)
 for(int i=0; i<number/2; i++)
{
     cout << spaces << symbol << endl;
}

Like I said before.. many ways to do this thing. Seems like you are pretty much done with ye' assignment. Let us know how it goes.

Clinton Portis 211 Practically a Posting Shark

You forgot to #include<iomanip>.

Clinton Portis 211 Practically a Posting Shark

look at my previous post. the problem is in line #8. make the correction and let us know what you did to fix the problem.

Clinton Portis 211 Practically a Posting Shark
//Provides ability to write to the dos console (cin/cout)
#include<iostream>

using namespace std;

int main()
{
     int input = 0; 

     cout << "Enter t or f: ";
     cin >> input;

     do{

          if(input == 't') 
          {
               cout << "True";
          }
          else if(input == 'f') 
          {
               cout << "False";
          }
          else
          {
               cout << "Incorrect entry.  Try again. \n";
          }
     
     }while(input != 't' && input != 'f');

     return 0;
}
WaltP commented: You need to STOP posting code for people. Their job is to write the code. You job is to stop trying to impress everyone with your coding prowess. -2
Clinton Portis 211 Practically a Posting Shark

Try looking it up.

Ok, I'll do the work for you:
http://www.cplusplus.com/reference/algorithm/random_shuffle/

template <class RandomAccessIterator>
void random_shuffle ( RandomAccessIterator first, RandomAccessIterator last );

template <class RandomAccessIterator, class RandomNumberGenerator>
void random_shuffle ( RandomAccessIterator first, RandomAccessIterator last,
RandomNumberGenerator& rand );

Rearrange elements in range randomly
Rearranges the elements in the range [first,last) randomly.

The function swaps the value of each element with that of some other randomly chosen element. When provided, the function rand chooses which element.

template <class RandomAccessIterator, class RandomNumberGenerator>
void random_shuffle ( RandomAccessIterator first, RandomAccessIterator last,
RandomNumberGenerator& rand )

{
  iterator_traits<RandomAccessIterator>::difference_type i, n;
  n = (last-first);
  for (i=2; i<n; ++i) swap (first[i],first[rand(i)]);
}

Parameters

first, last
Forward iterators to the initial and final positions of the sequence to be shuffled. The range used is [first,last), which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.
rand
Pointer to unary function taking one argument and returning a value, both of the appropriate difference type (generally ptrdiff_t). The function shall return a value between zero and its argument (lower than this).

// random_shuffle example
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <ctime>
#include <cstdlib>
using namespace std;

// random generator function:
ptrdiff_t myrandom (ptrdiff_t i) { return rand()%i;}

// pointer object to it:
ptrdiff_t (*p_myrandom)(ptrdiff_t) = myrandom;

int main () {
  srand ( unsigned ( time (NULL) ) );
  vector<int> myvector;
  vector<int>::iterator it;

  // …
Clinton Portis 211 Practically a Posting Shark

"vector subscript out of range"

Just based on that piece of information alone, I bet you are attempting to access a vector element that is larger than vector.size()

vector<int> v;

v.push_back(1);
v.push_back(2);
v.push_back(3);

//No bueno...  only elements 0,1, and 2 are currently populated:
cout << v[3];   //Access out of bounds
Clinton Portis 211 Practically a Posting Shark

but the verticle line must correspond with the number the user chooses

A loop is an excellent way to control dos console output based on user input. Additionally, use of setw() will allow you to scale the plus sign based on user specified dimensions.

Compile, run, and experiment with the following code:

#include<iostream>
#include<iomanip>

using namespace std;

int main()
{
     int size = 0;

     cout << "Enter size of plus sign: ";
     cin >> size;

     //Draw vertical line (top half)
     for(int i=0; i<size/2; i++)
     {
          cout << setw(size/2) << '*'  << endl;
     }

     //Now draw the horizontal line
     for(int i=0; i<size; i++)
     {
          cout << '*';
     }

     //Now draw the bottom 1/2 of the plus

     return 0;
}
Clinton Portis 211 Practically a Posting Shark

There are many ways to do the plus sign...

If you chose to use the setw() function, be sure to #include<iomanip>

You could make a char[] array of spaces (c-string)

If you chose not to use setw(), you could use a string literal consisting of a bunch of spaces....

Or you can make a string object and assign it a bunch of spaces.

You could use nested loops.. but in this case, for me personally, I would focus on constructing each part of the plus sign individually:

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

int main()
{

     //using a null-terminated c-string
     char spaces[10] = {'','','','','','','','','','\0'};

     //Build the vertial line (top half)
     for(int i=0; i<10; i++)
     {
          cout << spaces << '*' << endl;
     }

     //Now draw the horizontal line
     cout << "**********";

     //Draw the bottom half of plus
     //Just do the same thing as the top half

     return 0;
}

I know this isn't exactly what ye' are looking for, but it should give you an idea of just one way (out of infinite possibilites) of how to draw this thing...

You have many ways to do the same thing.. you could use multiple loops, you could use a nested loop.. you could use no loops at all. So how do you know what to use? Use what you think would be the easiest and most effective methods to accomplish the goals of your assignment.

Clinton Portis 211 Practically a Posting Shark

At first glance, your stuff looks good...

Have you tried #include<iostream> ??

Clinton Portis 211 Practically a Posting Shark
#include iostream
using namespace std;

int funcReturn(int& index);

int main()
{
     for(int i=0; i<3; i++)
     {
          cout << funcReturn(i);
     }

     return 0;
}

int funReturn(int& index)
{
     int a[3] = {33, 44, 55};
    
     return a[index];
}
Clinton Portis 211 Practically a Posting Shark
for(int i=0; i<10; i++)
{
     cout << i;
}

for(int i=10; i>0; i--)
{
     cout << i; 
}
Clinton Portis 211 Practically a Posting Shark

Being able to use loops effectively is an essential and very powerful programming technique.

Use a loop anytime you want to do a bunch of the same stuff over and over.

I can execute a million instructions with just a few lines of code:

//Print all numbers from 0 to 1,000,000
for(long int i=0; i<1000001; i++)
{
     cout << i << ' ';
}

But what if I only want let's say, only 5 numbers per line....

//Outter loop
for(long int i=0; i<200000; i++)
{
     //Inner loop
     for(int j=0; j<5; i++, j++)
     {
          cout << i << ' ';
     }
     
     cout << endl;
}

You can do pretty much anything you want to do with loops.. your imagination is your only limitation. Get down with loops and you will have a much more enjoyable time as a CS student.

Clinton Portis 211 Practically a Posting Shark

http://www.cplusplus.com/reference/string/string/find_first_of/

bool is_single_vowel(string word)
{
     //All words contain at least 1 vowel; find it:
     size_t found = word.find_first_of("aeiouAEIOU");

     //Handle Special Case:  If no vowel was detected, word must be using single 'y' as a vowel:
     if(found == string::npos)

          return true;

     //Attempt to find any occurance of a second vowel
     found = word.find_first_of("aeiouAEIOU", found+1);

     //If no second vowel was detected, return TRUE
     if(found == string::npos)

          return true;

     //Else word contains two or more vowels
     else

          return false;
}

Try upgrading your test condition in Line #28 to this:

if (word.size () > longest_word.size () && is_single_vowel(word))
Clinton Portis 211 Practically a Posting Shark

I'm not sure why you are getting that.. it may be due to incorrect switch syntax.. try using another variable name other than i.

You are on the right track btw. You need to wrap your head around basic loop operations before even picking up your assignment.

Here's a freebe for ye':

//draw a square (just one way out of infinite possibilities)

//draw top
for(int i=0; i<10; i++)
{
     cout << '*';
}

//draw sides
for(int i=0; i<10; i++)
{
     cout << endl << '*' << "         " << '*';
}

//draw bottom
for(int i=0; i<10; i++)
{
     cout << '*';
}

tips:

  • don't overcomplicate your switch, keep it simple. Use functions calls or small blocks of code.
  • When using nested loops, be sure to indent and always use braces.

Good attempt at experimental code you got btw.. good learning process taking place. Sometimes you just gotta get in there and try stuff and see what happens.

Clinton Portis 211 Practically a Posting Shark

try this:

string filename;

cin >> filename;

filename += ".dat";

outFile.open(filename.c_str());
Clinton Portis 211 Practically a Posting Shark

Run and compile this little program. Go through it line by line. Proceed no further until you understand the basics of using a simple loop. Then when you are comfortable, do experimentation with changing the loop conditions and loop contents to make it do new and exciting things:

#include iostream
using namespace std;

int main()
{
     int lines = 0;
     char c = '\0';

     cout << "Enter number of lines: ";
     cin >> lines;

     cout << "\nEnter a character: ";
     cin >> c;

     //Learn to use simple loops
     //Don't be afraid to try new things here
     // (make it loop backwards for example)
     //Your imagination is the only limitation.
     for(int i=1; i<lines; i++)
     {
          for(int j=0; j<i; j++)
          {
               cout << c;
          }
     
          cout << endl;
     }

return 0;
}
Clinton Portis 211 Practically a Posting Shark

IS THERE A BETTER WAY TO DO IT?

Look at lines #20 through #28 in my previous post for a better way to do this.

Yes, you will have to learn to use nested loops, which I believe is the goal of your assignment.

As for the overall design of your assignment, the important pieces of your program could look like this:

display_menu();

cout << "Enter shape to draw: ";
cin >> shape_selection;

cout << "Enter character to use to draw shape: ";
cin >> char_selection;

cout << "Enter odd number of lines to draw: ";
cin >> lines;

switch(shape_selection)
{
     case 1:  draw_tri(char_selection, lines);
     break;
     case 2:  draw_upsidedown_tri(char_selection, lines);
     break;
     case 3:  draw_rectange(char_selection, lines);
     break;
     case 4:  draw_plus_sign(char_selection, lines);
     break;
     default:  menu_error();
}

//Function definitions
void draw_tri(int char_selection, int lines)
{
     //Use a nested loop to draw a triangle, line at a time, top to bottom
     //Copy and paste the triangle algorithm from my previous post
     //No thinking required.
}

void draw_upsidedown_tri(char_selection, lines)
{
     //Use a nested loop to draw an upside-down triangle
     //Refer to my previous post for a triangle drawing algorithm
     //Alter the loop conditions to draw the triangle upside-down.
}

void draw_rectangle(char_selection, lines)
{
     //draw top of rectangle
     //Using a loop, draw left side, bunch of spaces, then draw right side.  Newline each loop iteration.
     //draw bottom of rectangle
}

void draw_plus_sign(char_selection, lines)
{
     //use a loop to draw vertical top half of plus, newline each loop iteration.
     //draw the horizontal row of …
Clinton Portis 211 Practically a Posting Shark

You are losing the fact that there is an array. All the function knows is a pointer was passed in. It has no idea how many locations are associated with the pointer. You need to also pass the size into the function.

void myfunction(int array[], int array_size)
{
    //stuff
}
Clinton Portis 211 Practically a Posting Shark

Here is an in-depth discussion I googled concerning the dangers of using sizeof(array)/sizeof(arraytype) in order to get current length of an array:

http://www.gamedev.net/community/forums/topic.asp?topic_id=345898

Some alternatives to consider:

  • Dedicate a 'size' variable to hold number of entries made into an array.
  • Use null-terminated c-strings; get array length using strlen().
  • Use an STL container such as String or Vector, use a size() member function to return string length.
Clinton Portis 211 Practically a Posting Shark

Winsock is very popular, easy to use, and is a very good skill to have on the ol' resume. Companies will love you.

Clinton Portis 211 Practically a Posting Shark

Your 'function-local' variable named TotalMPG we be created and thusly destroyed with every call of the MPG() function.

Try creating a class variable that will retain the odometer reading.

Clinton Portis 211 Practically a Posting Shark

it is possible. i did not include my usual disclaimer: "The code provided is uncompiled, untested and may contain simple, easy to fix errors." The theory is sound. I did most of the thinking for you. Please make at least some sort of attempt to resolve any simple syntax errors. Any effort on your part = good.

Clinton Portis 211 Practically a Posting Shark

You are attempting to implement the answer using a linear method. Try using a nested loop and I think you'll have the results ye' be looking for:

int lines = 0;
char c = '\0';

//Prompt for user input
do{
     cout << "\nEnter an odd number of lines of triangle to be drawn: ";
     cin >> lines;

     //Test user input
     if(! lines%2)
     {
          cout << "\n\aNumber entered is even.  Please enter an odd number.";
     }
}while(! lines%2);

cout << "\nEnter chararcter to be used to draw triangle: ";
cin >> c;

//Draw ye' precious triangle
for(int i=0; i<lines; i++)
{
     for(int j=0; j<i; j++)
     {
          cout << c;
     }
     
     cout << endl;
}
jonsca commented: Arg matey, Cap'n Portis is back +2
Clinton Portis 211 Practically a Posting Shark

Useful tips:

you can consolidate lines 13 through 33, and eliminate lines 35 through 44 by doing this:

// Initializing the eight choices.
	int iChoice1 = (rand() % 8) + 1;
	int iChoice2 = (rand() % 8) + 1;
	int iChoice3 = (rand() % 8) + 1;
	int iChoice4 = (rand() % 8) + 1;
	int iChoice5 = (rand() % 8) + 1;
	int iChoice6 = (rand() % 8) + 1;
	int iChoice7 = (rand() % 8) + 1;
	int iChoice8 = (rand() % 8) + 1;

Furthermore, keeping your choices in array format would continue to simplify your code:

int choices[8];

for(int i=0; i<8; i++)
{
     choices[i] = (rand()%8) + 1;
}
Clinton Portis 211 Practically a Posting Shark

You need to refine your question before we go all out w/ a bunch of code to give you what may or may not be the correct answer.

You unclear in some aspects of your question; for example, you state that you require an 'odd number' input from the user, but then later give 'rectangle' and 'plus sign' as possible shapes that could be derived from user input (which have even number sides).

Additionally, when the user enters an odd number, does this input correspond to the number of sides of the shape, or the number of characters needed per side to create a triangle?

Clinton Portis 211 Practically a Posting Shark

I can't read this C style file i/o.

Clinton Portis 211 Practically a Posting Shark

1. try opening the file in binary and see if you still experience the same type of behavior

2. without seeing your code, i am not sure what you are using.. but you may have problems with these ascii values exceeding the 8bit capacity of the char data type.

the default signed char will allow ascii values up to 127 without experiencing overflow. an unsigned char will allow ascii values up to 255.

most unicode implementations allow use of a WORD type that will support 16bits which I believe is capable of handling all char sets.

one solution if you want to stick to native c++ types, would be to use a wchar_t which is 2 or 4 bytes, depending on your operating system.

Clinton Portis 211 Practically a Posting Shark

Probably the most efficient method that I could think of (in terms of line of code) would probably be something like this:

#include<algorithm>
#include<cstring>

char line[] = "Dance, too much booty in the pants.";
int size = strlen(line);

replace(&line[0], &line[size], ' ', '_');


replace() from <algorithm>

Clinton Portis 211 Practically a Posting Shark

I'll tell you now, there is absolutely nothing wrong with an older woman. I ask that you expand your horizons to the include the cougar age group.

Next time you see her, tell her that you want to 'sink her battleship.'

Clinton Portis 211 Practically a Posting Shark

shes out of town,

so she's out of town 'taking care of her needs' while you are here having to learn a somewhat complex object oriented programming language in false dellusional hope that you might get a piece of the action.

i can tell you now, that if you haven't closed the deal it's not going to happen.

next time, she has to 'pay up front' if you know what i mean.

Clinton Portis 211 Practically a Posting Shark

I'm sorry to say this hombre... unless she is giving it up, you better grow a pair and tell her to do her own @#@$!@#$ homework.

(however, if she is giving it up I'll be glad to assist you in anyway i can)