Duoas 1,025 Postaholic Featured Poster

Hmm, I hadn't considered different versions. I'm using QBasic version 1.1, and everything is just piled in one folder on my G: drive. I run it from the default windows command prompt.

What version are you trying to work with?

Duoas 1,025 Postaholic Featured Poster

I'm running XP and QBasic and help work fine for me. I can't reproduce your problem. Sorry I can't help you further...

Duoas 1,025 Postaholic Featured Poster

No, i use XP and here is the code I was trying to use http://www.planet-source-code.com/vb/scripts/ShowCodeAsText.asp?txtCodeId=10405&lngWId=3
Also I am the admin on my pc so I should be able to do whatever I like with the files shouldnt I?

Believe what you like. Your error message is ld returned 1 exit status which explicitly means your linker is failing for some (unspecified) reason.

Check to make sure the compiler is correctly configured to use the linker.

Also, admin doesn't mean you have unfettered access. Just privileges sufficient to override access restrictions. That said, my first, off-the-cuff diagnosis was probably premature.

Duoas 1,025 Postaholic Featured Poster

Use the ord function. print ord('A') Prints the number 65 to the console.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

It isn't the code that's complaining, it is the linker (ld).
Most likely you are trying to write to a file that is read-only, or read or write a file that you don't have access rights to. Are you using linux?

Duoas 1,025 Postaholic Featured Poster

The file QBASIC.HLP is not a Windows Help file, so WinHelp cannot open it.
You need a program named HELP.COM. If you google olddos.exe you should find the Microsoft package that contains QBasic and other utilities, like Help.com.

Hope this helps (pun intended) :icon_lol:

Duoas 1,025 Postaholic Featured Poster

Hey again zandiago. Watch your syntax.

switch (sentence[ i ]) {
  case 'A': case 'a':
    total += A;
    ++numChars;
    break;
  case 'C': case 'c':
    total += C;
    ++numChars;
    break;
  ...
  }

You are correct in that if a char is not in the switch then nothing is added to your total (nor numChars).

I would also add a case for whitespace and other end of word markers to reset total and work on the average stuff per word.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Actually, you've got things just about right. The problem is that you are calling main() from the other functions. Don't do that.

In between lines 16 and 17 add: while (TRUE) { end the while statement between lines 41 and 42: } Then, get rid of every instance of main(); . That is, get rid of lines:
39, 52, 53, 55, 71, and 85.

You might also want to reconsider why so many of your functions return a value. For example, checkPrime() always returns zero, and the return value is ignored anyway (line 28), so just make it void checkPrime( int ); and

void checkPrime( int number ) {
  int n=number, den;
  for(den=2; den*den<=number; ++den){
    if(number%den==0){
      printf("Your number is not prime.\n It is divisible by %d.\n", den);
      return;
    }
  printf("Your number is prime.\n");
  }

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Er, C languages don't permit subfunctions. Try this:

#include <iostream>

void run();
int process( int larger, int smaller );
bool isOdd( int number );

void main() {
  char c;
  do {
    run;
    for (c = 'x'; (c != 'Y') && (c != 'y') && (c != 'N') && (c != 'n');) {
      std::cout << "Would you like to run again (yes/no)?" << std::endl;
      std::cin >> c;
      }
    } while ((c != 'N') && (c != 'n'));
  }

void run() {
  int numA, numB, x, result;

  // Get the two integer numbers from the user
  std::cout << "Please enter two integers to multiply:" << std::endl;
  std::cin >> numA >> numB;

  // Force numA to be the larger number:
  if (numB > numA) {
    x = numA;
    numA = numB;
    numB = x;
    }

  result = process( numA, numb );

  std::cout >> "ZanDiego  Class 12  Oct 16, 2007 2:30pm\n";
  std::cout << numA << " times " << numB 
            << " by conventional math = " << (numA * numB) << std::endl;
  std::cout << numA << " times " << numB
            << " by Brown's method = " << result << std::endl;
  }

int process( int larger, int smaller ) {
  // your code here
  }

bool isOdd( int number ) {
  if ((number % 2) == 1) return true;
  return false;
  }

You'll notice I've only used code that you have supplied except for:
- I've improved a few of the prompts to better language
- The main() function

Duoas 1,025 Postaholic Featured Poster

Ah, yes, you're right. I didn't crunch the examples like I should have. The assignment should have said something like "the initially larger number" or some such. Heh. :$

Duoas 1,025 Postaholic Featured Poster

Hmm, if you say so. The program specification appears to read the other way to me. You might want to check with your professor to be sure.

It looks like you have got good function names. All the interesting stuff happens in process, so concentrate there.

Good luck!

Duoas 1,025 Postaholic Featured Poster

First: Only include stuff you need. Go ahead and get rid of everything except iostream. (You don't use any I/O manipulators, you don't use any C math functions, you don't read or write to files, and you don't use any std::strings.)

Second: This point probably isn't obvious at first glance, but you should be using int instead of double. All the math taking place is integer arithmetic and all the example output lacks fractional parts.

Third: "Write a program using functions". You are missing functions (well, besides main). Try to divide your program up into simple functional parts:

main(): in a loop, call a function that asks for two numbers and does the assignment stuff, then ask the user if he wants to do it again. If not, quit the loop and quit the program.

functionA(): ask two numbers from the user. In a loop, complete the assignment's 'accumulator' stuff. Print the results.

functionB(): do the stuff that actually modifies the accumulator...

Make sure to come up with better function names than i've given you here. Also, don't use global variables. Make the functions take arguments and return values.

Finally: You need to get out a piece of paper and clearly write down the exact actions that the functionB() takes for each possibility. The accumulator will be modified one of two ways based on whether or not the larger number is odd or even. Do this and you'll breeze through this assignment.

Duoas 1,025 Postaholic Featured Poster

You used cout yourself in your original program. Somewhere at the beginning of your code you probably have a line like

using namespace std;

which teachers persist in teaching people.

The cout object belongs to the std namespace, which you make active with the using statement. I typed it explicitly just to show good coding practice...

Enjoy!

Duoas 1,025 Postaholic Featured Poster

The problem is so simple you'll laugh...

Your loop says:

while there is no file failure (eof):
    abc <-- read next record
    display abc

What happens is this:
Read record one (no file read failure), display record one.
Read record two (no file read failure), display record two.
...
Read record N (no file read failure), display record N.
Read record N+1 (couldn't: file read failure), display record N (since abc == last record)
While loop terminates.

You need to test the file failure before displaying the record. There are a zillion ways to rewrite this, so I offer my way:

while (true)
{
  if (! file.read( ... )) break;
  abc.showdetails();
  std::cout << std::endl;
}

Hope this helps.