MyrtleTurtle 52 Junior Poster

The error I get is 'address of while(AreThereMore) will always evaluate to true.'

You need the ()'s when calling the function.

Also I see a couple of things in your AreThereMore() function:

If answer is not true, you need to set it to false. And when you compare you need to check each answer. Instead of

if (reply == 'Y'||'y') //this will always evaluate to true, I believe...because it is asking[I] if reply == 'Y' [/I]OR [I]if 'y'[/I]
{ 
answer=true; 
cin.ignore();
} 
else(reply== 'N'||'n');
{

You can say:

if (reply == 'Y'|| reply =='y')
{ 
answer=true; 
cin.ignore();
} 
else if(reply== 'N'|| reply =='n')
//or just put the else, without a comparison:
else{
//
}
MyrtleTurtle 52 Junior Poster

Actually, I have never used while(!infile.eof()) { Sorry for giving not-so-great advice here. I haven't seen it used any other way though.

Using this syntax, when the while loop ends you can evaluate using eof().

How would you do that? With an if statement? while(infile >> input) { is a little confusing to me. What if you need to read things from the file into other variables besides input? Won't that mess it up? If not, why not?

Is there anything wrong with this: while(infile.good()) { ?

MyrtleTurtle 52 Junior Poster

EOF means end of file. You can check for it like this:

while(!infile.eof())

It looks to me like you have closed your file and then tried to read from it.

infile.close();	//Force closes the file

while (infile)
{
	if(
MyrtleTurtle 52 Junior Poster

Here is one way of reading from a text file and displaying the contents:

string sentence;
    string readSentence;
    
    //open file to read
    ifstream inData;
    inData.open("YourFileName.txt");
    
    //read first line from the file
    getline(inData, readSentence);

    //show error if file not found
    if(!inData){
          cout<< "Can't open input file.\n";
          getchar();
    }
    
    //while there are more lines to read from file
    while(inData){     
          sentence = readSentence; 

          //write data to screen     
          cout << sentence << endl;
          
          //read another line
          getline(inData, readSentence);
    }
    
    //close file
    inData.close();
MyrtleTurtle 52 Junior Poster

You're trying to calculate before you get the input. This line should go after you get the input to assign a value to price and quantity.

total = price * quantity * tax;
MyrtleTurtle 52 Junior Poster

im trying to call the functions above int main() but my compiler is saying that i am redeclaring them.

You declare functions outside of int main() but you call them within int main(). So if you're trying to call them outside of the main() function, then it (the compiler, I mean) would think you're trying to declare them again.

Also, it is much easier to see what the problem is if you post your code.

MyrtleTurtle 52 Junior Poster

You don't even need to pass in grade or tot_quest into your functions if you are getting their values within the function. You can just define them within the function (if you don't need them anywhere else in the program.)

double calculateGrade(double grade)
{
    int quest_corr, tot_quest;
    grade = quest_corr/tot_quest;
    cout << grade;
return grade;
}

This will not give you the correct answer because you define quest_corr and tot_quest here, but do not give them a value. Then you use them in a calculation. I would define the variables, get the values and then pass them in, or get the values within the function as you do with tot_quest in your other function.

MyrtleTurtle 52 Junior Poster

If you make your 1st textbox invisible, you can assign the value of each button to that textbox (whenever you click a button, just as you have it now) and then when you click on any other textbox make it's value equal to the first one.

It's not the exact thing you want done: Click on a textbox then a button and assign that button's value to the textbox.

It is almost the same though: Click on a button and then a textbox and assign that button's value to the textbox.

Edit: apegram's answer is probably way better than mine, sorry!

@apegram, no offense, and I certainly do not mean to hijack someone's thread, but...

I cannot get your code to work. It gives me errors:

It doesn't like the commas on these lines, but also complains after I change them to ;s as it suggests.

buttons = new List<Button>() { button1, button2, button3, button4, button5 };
            values = new List<string>() { "A", "B", "C", "D", "E" };

            // temp list of boxes
            List<TextBox> boxes = new List<TextBox>() { textBox1, textBox2, textBox3, textBox4, textBox5 };

Here's the other error:
'WindowsApplication1.Form1.ActiveTextBox.set' must declare a body because it is not marked abstract or extern

MyrtleTurtle 52 Junior Poster

I have loads of text boxes (coloured blue) and some buttons. Right now if i click a button it only assigns the frame to textbox1. How do i make it assign to the box that my cursor is on (when i click the box)

If I read this correctly, what you want to do is to assign whatever text is in the first box into the second one as well, when you click the second box?

(Using Visual Studio C# Express Edition 2005...yeah I know I need to update) You can do this:

Go to design view. Right click on textBox2. Click Properties (if it isn't already showing). Look to the right, where the properties are displaying. Click on the lightning bolt (events). Scroll down to MouseClick. Double click on it, which should take you to the code & add the MouseClick code. Then just write inside it whatever you want to do when the user clicks the mouse.

private void textBox2_TextChanged_1(object sender, EventArgs e)
      {
   //         textBox2.Text = "Whenever you write something in the box and hit enter, this text will appear.";
          //the next part did not work until I commented this out
//but you had nothing there anyway so it shouldn't matter for your code
    }

        private void textBox2_MouseClick(object sender, MouseEventArgs e)
        {
            textBox2.Text = textBox1.Text; //this will make the text in the 1st box appear in the 2nd one when the user clicks this box
        }
MyrtleTurtle 52 Junior Poster

Yes you can.

Oops. Sorry. Thanks for the correction. :$

Fbody commented: A point for willingness to learn. +1
MyrtleTurtle 52 Junior Poster

Edit:
...it does seem to work when I compile your code, as is. The first line is off, but that's only the formatting (needs to go a bit to the right).

However, I do see this:

int isleapyear;

else if (month == 2 && isleapyear)

You can't compare an int value in your if statement. You could compare it if it was a bool though.

MyrtleTurtle 52 Junior Poster

One equal sign assigns a value. Two equal signs compare values.
Change

if(c[i]%2=0)

to

if(c[i]%2==0)

and it should get rid of that error.

But you probably shouldn't use goto.
You can use a for loop or a while loop or even a do while loop instead.

MyrtleTurtle 52 Junior Poster

Oh yeah...I was going to say that, too. Don't use goto.

And, you can't actually control what the user will input. But your program can handle it if they do not enter what you want them to, if you add the code I suggested. :)

MyrtleTurtle 52 Junior Poster

I am not sure about the first part but I can answer the second part. One way to ensure that the input is good (the user enters a number) is to do this:

void clearError(long int& num){ //pass number in by reference so it can be changed within the function
    cin.clear(); //clear the error state
    //ignore characters left in the buffer up to and including the new line character
    cin.ignore(numeric_limits<streamsize>::max(), '\n');      
    //allow them to reenter number
    cout<<"That is not a number. Try again: ";
    cin>>num;
}

int main ()
{

	cout<< " WELCOME TO THE 2 BASED FACTORIAL CALCULATOR " << endl << endl;

start:;

  long number;
  cout << "Please type a number: ";
  cin >> number;
  
  while(!cin.good()){
     clearError(number);    
  }

I like to put it in a function so it can be reused, but you don't have to do it that way.

MyrtleTurtle 52 Junior Poster

You can also create and open your file this way, which is more like what you're doing:

ofstream myfile;

    string filename = "MyNewFile2.txt"; //or whatever name you want
    myfile.open (filename.c_str(), ios::out);
MyrtleTurtle 52 Junior Poster

You can create a file and write to it like this:

#include<iostream>
#include<fstream> // for file reading & writing
#include<conio.h> //for getch()

using namespace std;
int main(){
fstream myfile; //you can use ofstream for writing to a file and ifstream for reading from a file...& probably should
    myfile.open ("MyNewFile.txt"); //put whatever name you want
    if (!myfile) //um, why do you try to write to a file that has not opened?
    {
     //I would show an error if the file doesn't open
     cout<<"File not found.";
//        myfile.close();  how can you close it if you don't have one?
//        myfile.open (filename.c_str(), ios::out);
//
//        avatar.name = name;
//        avatar.init();
//        myfile << "Name = " << avatar.name << endl;
//        myfile << "hp = " << avatar.hp << endl;
//        myfile << "mana = " << avatar.mana << endl;
//        myfile << "level = " << avatar.level << endl;
//        myfile << "strength = " << avatar.strength << endl;
//        myfile << "intelligence = " << avatar.intelligence << endl;
//        myfile << "wisdom = " << avatar.wisdom << endl;
//        myfile << "dexterity = " << avatar.dexterity << endl;
//        myfile << "charisma = " << avatar.charisma << endl;
//        myfile.close();
    }
    else
    {
       // cout << name << " already exists" << endl;
       myfile<<"write something to the file.";
       cout<<"Writing to file.";
       myfile.close();
    }
getch();
return 0;
}
MyrtleTurtle 52 Junior Poster

Your problem is that this for loop never runs. You have the greater than/less than sign mixed up.
change

for(n=1; n>=100; n++)

to

for(n=1; n<=100; n++)