Red Goose 21 Junior Poster

I smell homework.

Read up in your reference book on implementation of pointers.

Red Goose 21 Junior Poster
if (conversion !=1|| conversion !=2|| conversion !=3|| conversion !=4|| conversion !=5|| conversion !=6)

Can be changed to

else

Since the above is implied through the preceding code.

Also be careful with your brackets. Line 73 is the end of your do loop and line 76 is the end of int Main(). You also have one surplus bracket. Don't forget your return statement for int Main() either.

Red Goose 21 Junior Poster

I think there's a char code that you can use. (like /20?)

Blank space IS a char.

#include <iostream>
using std::cout;

int main()
{
 char c = ' ';
 cout <<"Space" << c << "is" <<c <<"a"<<c<<"Character.";
 cout <<"\nAscii code = " << int(c);
 return 0;
}

Note the space between words.

If you specify blank space, OP, then you should be good to go, though I suggest using the int values instead, it will look much cleaner.

ASCII Values

Red Goose 21 Junior Poster

Just open an output stream and save them to a text file, you're already halfway there.

Red Goose 21 Junior Poster

Yup, at the moment it does nothing. But i've planned to give meaningful default values later. But i dont think the error has to do anything with the empty string parameters. isnt it?

No, I was just curious why you would take in parameters if you're going to redefine them anyways.

Red Goose 21 Junior Poster

Your array is not two-dimensional.


I also suggest using a variable for input as opposed to just defining every possible outcome. You're setting yourself for one tedious and hard to follow jumble of code.

An example:

unsigned short x,y;
cin >> x >> y;
myArray[x][y]= 'X'

This takes the code that was 13 lines long and makes it three long.

Red Goose 21 Junior Poster
Person::Person(string first = "", string second = "")

Out of curiosity, what are you tying to accomplish with your parameters?

Red Goose 21 Junior Poster

How can your application send you anything without some form of internet activity?

Red Goose 21 Junior Poster
#include<iostream>
#include<windows.h>
#include<conio.h>
#include<strings.h>

using namespace std;

int main();
void repeat();
void worked();

string s1;
string s2;
string s3;

int main()
{
        repeat();
}

void repeat()
{
    string s3="n";
    cout << "Would you like to perform another operation?\n";
    cin >> s3;
    if((s3=="Y" || "y"))
    {
        worked();
    }
    if((s3=="N" || "n" || "no" || "No"));
}

void worked()
{
    cout << "Hey guys, it worked!";
    Sleep(5000);
}

Who reviewed your code and told you it would work? I see several problems up front:

1. Half your inclusions are not necessary. The only inclusions you need are Iostream and strings.h.

2. You have a prototype of your main function, which is completely unnecessary. Prototypes exist so that if you call a function before it is actually defined in your code, your compiler knows it exists and won't throw an exception at you. Since nothing is called before Main, it's just a waste of space. Your main function also doesn't have a return call.

3.Your "Repeat" function isn't actually repeating, since it's not looped or recursive.

4.

if((s3=="Y" || "y"))

still needs to be changed to

if((s3=="Y") ||(s3== "y"))

5. Your second if statement does nothing. It checks for a condition but nothing is done if the condition is true.

6. Usage of the "sleep" function is not necessary. I'm not even completely sure what you're trying to do with it.

7. You declare 2 strings you don't use.

And this is just …

Red Goose 21 Junior Poster

You're asking for input of a character but your variable is an integer, which can only be numerical. The problem your seeing is common to mis-matched variable types.

A for loop is also the incorrect type of loop for this particular function. The loop outlined above would serve your purpose better.

Also note that you're asking for upper-case inputs ("E, A, G, P"), but your function is actually looking for lower case inputs ("e, a, g, p"). If you entered "E" it would give you the "rating invalid" message instead of the E rating.

Finally, the System("pause") line serves no real purpose.

Red Goose 21 Junior Poster

1. You're not using a char variable, you're using an integer variable. Integers are strictly numerical.

2. Character variables can only hold 1 character. This is due to size limitation of the variable. You will need an array characters to accept input with more than one character.

If this sounds a bit over your head then don't worry about it, just ignore this part for now, your class should cover all that stuff.

The reason is so that I can have the maximum and minimum on the dice changeable.
Unfortunly it complains on:
`minpoints' undeclared (first use this function)
`maxpoints' undeclared (first use this function)
However I have declared that int minpoints = 1, maxpoints = 6 in a int earlier.

Variables are function specific, meaning that unless you:
1.Used the old variables as parameters for the function
or
2.Declared the variables globally. (not the best option)

Your variables will not exist in this new function. Have you learned about function parameters yet?

#include <iostream>

using std::cout;
using std::endl;
using std::cin;

int Add(int x, int y);

int main()
{
 int x,y;
 cout << "Enter value one" << endl;
 cin >> x;
 cout << "Enter value two" << endl;
 cin >>y;
 int result = Add(x,y); // Passing the variables as parameters.
 cout << "Their sum is: " << result;
 return 0;
}

int Add(int x, int y)
{
 int sum = x + y;
 return sum;
}

Have you …

Red Goose 21 Junior Poster

You have your array declare globally, I'd change that.

Also, try declaring the range of the array inside your function. I'd imagine by the nature of multidimensional arrays your compiler will want that specified.

Example:

myfunc(int array[0][5]) //change the '0' to '5'.
Red Goose 21 Junior Poster

You're skipping your if loops:

if (gamechoices == "Attack" || gamechoices == "fight" || gamechoices == "kill");

The semicolon ";" at the end terminates the if statement. You need to place anything that will be executed within your if loops within brackets "{ }". It's a common mistake since intuition tells us that semicolon means "end line", when it actually means "end of statement". So, what's happening is your if statements are checking, and, if true, doing nothing, ending, then executing your do loop.

Red Goose 21 Junior Poster

1.Make sure everything is kept as a character; use some denotation as terminator so you can have multi-digit numbers without much difficulty.


2.Convert these chars to their ASCII equivalent integer. If the ASCII value of the char is between 0-9, give it precedence over any non-integer character. A simple boolean variable will suffice. Make sure your loop is checking for those terminators so you can keep multi-digit numbers together.

3.Use a standard sorting algorithm, I'm sure you've already set one up for your initial program.

Red Goose 21 Junior Poster

Hi luce..

I try your code already..
once compile I get error message like below show..

******************************************************************
error C2065: 'Image' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'image'
error C2065: 'image' : undeclared identifier
error C2065: 'GetEncoderClsid' : undeclared identifier
error C2228: left of '.Save' must have class/struct/union type
******************************************************************
Please help..

am I need to include any header..??

He wasn't writing your code for you, he was giving an example of how to implement the functionality. No one will do your code for you, as stated here.

As stated, you would need to open the image file and output with the proper encoding. Here is an article of MDSN on how to do it as well. A lot of options are available to you.

Red Goose 21 Junior Poster

sir how do I assign the values of my variables when using arrays? I want something like this to happen

string seatnumber = "1"

this is just an example. In Arrays do I have to assign values to 200 seatnumbers one by one too?

The syntax of array assignment is as follows:

arrayname[index] = assignment
Red Goose 21 Junior Poster

Why the use of strings? Boolean statements would work just as well(better even):

bool seat[200];

And then...

if (seat[input] == 1)
  cout << "Seat Number" << input << "is reserved. Please choose another.";
 else 
   seat[input] = 1

And there you go. Your 500 hundred line case statement is not necessary and you've gone from taking the space of a billion strings to a few boolean variables.

Red Goose 21 Junior Poster

alright thanks a lot for your help. My only other question is top() a built-in function or is it a function that you have to declare/create yourself?

top() is a member function of the stack class. You don't need to create your own.

Oh, also, remember you want to declare your stack and queue with

#include <stack>

.

Declaring it with double quotes makes the compiler look in the same folder as your program. You want to use the STL header.

Red Goose 21 Junior Poster

So i should read in character by character instead of the whole string?

Of course, If you read the whole string, it will equal the same no matter what kind of container you use.

Also, we were taught that push/pop is only associated with stack and enqueue/dequeue is associated with queue, so it is a little confusing to me.

push and pop particularly are, however, other STL containers use similar wording like "push_back" or "pop_back".

So this is my thought process: When you push from a stack, the string "ABCD" will be in order in that stack. When you pop, that string will be "DCBA." Is this correct?

Remember, when you're "poping", you're just deleting the variable in front, so you can access the next one in the stack. The command "stack.top()" is what actually accesses the variable.

Other than that, you're right, because a stack displays the newest variable first and the oldest last, and if you enter "ABCD" D is the newest, while A is the oldest.

Red Goose 21 Junior Poster

Your divides function takes two int objects as parameters, and returns an int.

Accordingly, you must call it like this:

returnedInt = divides (someInt, someOtherInt);

where returnedInt, someInt and someOtherInt are all of type int.

Or, he could use an if statement to check the returned value like so:

if(!divides(input1,input2)

Which would return true if the function = 0 (false).

Red Goose 21 Junior Poster

so are you saying that the original string is each of the characters pushed, and the characters popped out of the stack is the reverse string?

If so, how do I pop the characters into a string?

maybe like

revString = Pop(oWord)
i--
?

and queue is part of the assignment, so i have to use it.

But i agree i dont understand why we have to use both

"Pop" is an STL function that deletes a value in an STL container. You don't need to "pop" anything in your string. You don't need "revString" at all is my point. If you're using both containers and (I assume) your containers hold char variables, you just need to compare both your queue and your stack to ensure that they're equal.

if (stack.top() != queue.front())
  isEqual = false;

Do this until one of them is empty (doesn't matter which, they should be the same size). If "isEqual" is false by the end, then, clearly, the word is not a palindrome. A simple if statement is all that's needed at that point. Assuming you're populating your containers properly, there shouldn't be much else to it.

The point of this exercise seems (to me) to teach you the difference between stack and queue. Remember, stack is "last come, first serve" and queue is "first come, first serve", meaning, when you access a variable in a stack, you're accessing the newest variables to come into the stack, while in a queue, …

Red Goose 21 Junior Poster

Why use a queue at all? The queue is only gonna return the same thing as your string in the first place.

Remember the nature of a stack. A stack is somewhat unfair and believes that the last person to come should be the first to go. Think of a "stack" of objects. You always place both on top of the stack, and take off the top of the stack. Because its "last come, first serve", all you need to do is fill a stack and compare that to your original string.

Red Goose 21 Junior Poster

Just to clarify, the prototype is what tells the compiler that the function exists, so if another function calls that function before it is actually defined, the compiler knows it exists and doesn't need to throw an error at you. A class declaration (as you've shown), is the same thing. It includes more than just the class name out of necessity, since when you call the class inside your code, you'll usually call member functions and variables.

So, no, you can't declare a class like that, since it doesn't give the compiler the proper information.

Red Goose 21 Junior Poster

So are you saying that you can generate closed-source code, and use a license of your choosing for it, so long as you have an appropriate notice concerning, and provide access to, the MySQL License and Source in compliance with the GPL?

Read more about the GPL here.

Red Goose 21 Junior Poster

that is what i thought but it is not working--

i rewrote the last line of code

digit_two+=7%10; //add digit_two to 7 and mod 10

digit_three+=7%10; //add digit_three to 7 and mod 10

digit_four+=7%10; //add digit_four to 7 and mod 10

cout <<"Encrypted digits:" << digit_three digit_four digit_one digit_ two <<endl; // display encrypted numbers

but now the confiler is give me this mess


1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2146: syntax error : missing ';' before identifier 'digit_four'
1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2146: syntax error : missing ';' before identifier 'digit_one'
1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2146: syntax error : missing ';' before identifier 'digit_'
1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2065: 'digit_' : undeclared identifier
1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2146: syntax error : missing ';' before identifier 'two'
1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2065: 'two' : undeclared identifier
1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2563: mismatch in formal parameter list
1>f:\program class\tutorial 4\christine gershen tutorial 4\christine gershen tutorial 4\4.cpp(44) : error C2568: '<<' : unable to resolve function overload
1> d:\program files\microsoft visual studio 9.0\vc\include\ostream(974): could be 'std::basic_ostream<_Elem,_Traits> &std::endl(std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=wchar_t,
1> _Traits=std::char_traits<wchar_t>
1> ]
1> …

Red Goose 21 Junior Poster

You're doing the calculations before you're getting the number, and since num will be 0 at that point, tens digit and ones digit will always equal zero, no matter what. You need to take in your number THEN do the calculations for tens digit and ones digit.

Red Goose 21 Junior Poster

Gah, so confusing. I'm gonna learn a bit more, then come back to this, because i dont really understand at the moment.

Thanks for the help anyway, ill refer back to this later.

You should probably find a textbook or some sort and learn from that. If you follow it step by step, that code should seem simple in no time.

Red Goose 21 Junior Poster

To see every available character, compile and run this code, if you can make the "cent" symbol in a char or string, it'll be there:

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
 char c;
 for (int x = 0; x <= 255; x++ )
 {
  c = char(x);
  cout << setw(3) << x << " = " <<setw(1) << c << " ";
  if ((x % 8 == 0)&&(x > 1))
   cout << "\n";
 }
 return 0;
}
Red Goose 21 Junior Poster

Well, c++ will be just as complicated as Java and I believe Adobe Air will require you to use Java anyways,

Red Goose 21 Junior Poster

Yes, that's right.

Red Goose 21 Junior Poster

This is an error you receive when your compiler can't find the entry point to your code.

Your main function cannot be inside a class. How will you access it inside a class? What will call it? You need your main function to be immediately accessible so your program can start!

Red Goose 21 Junior Poster

What specifically do you mean by "click some button"?

Red Goose 21 Junior Poster

Your if statements aren't doing anything to begin with. You may want to carefully reexamine if statement implementation.

Red Goose 21 Junior Poster

EDIT: Well, are your files in the right place? Your input file should be in the same directory as the "exe".

Red Goose 21 Junior Poster

No I tried everything,I can't get it.

What, specifically, don't you get? How to take input? You take input the same you would with "cin".

Red Goose 21 Junior Poster

Well, this isn't C++.

Also, I don't fully understand the question. You simply specify that Column before you perform the action. There's not much else to it.

Red Goose 21 Junior Poster

How do I take input from the file,according to my prescribed book it should be:

while(in_stream >> numMembers >> ordered >> wine >> billAmount)

but it is not working.

How do you take input with "cin"? It's the same concept. They're both stream.

Red Goose 21 Junior Poster

No I removed it is not supposed to be there,I just out it there to try.

I used your code thanx but look what I have now,my program is still not working.What am I doing wrong.

while(!in_stream.eof())
    {
        totalMembers += numMembers;
        totalBillAmount += billAmount;
        average = totalBillAmount / totalMembers;
        if((numMembers > 5) && (ordered > 4) && (wine > 2))
        {
        totalOrdered++;
        totalCommission = (billAmount / 3 * 100);
        }
    }

You're not taking any input from your file.

Red Goose 21 Junior Poster

Well, right now, you're only assigning the input to billAmmount. As it stands, totalMembers will always be equal to zero. 0 + 0 = 0. If you mean to take input for each variable then apply those to the total variables you may want to change your loop to look for the eof() of your input and simply take in input to each variable in the order in which they occur in the file.

while (!in_stream.eof()) //eof stands for "End of File".
{
 //inputs for each variable
 
 //mathematical assignments
}

Oh, and one last thing, what is:

ifstream inout;

for?

Edit(again): You do know you're billAmmount is the input and your totalBillAmmount is the sum of all the bills, right? You're only printing the BillAmmount.

Red Goose 21 Junior Poster

We'll need to see your code to know what's wrong with it.

Red Goose 21 Junior Poster

It may be because you're using pointers instead of string iterators.

Red Goose 21 Junior Poster

I'm so sorry...thanks for your patience I was writing this at two different times and didn't realize I hadn't checked to see if all my variables matched up with one another

so now that the problem with p is gone I still come up with an error message with the corrupted array only sometimes when I run it

why would it do that and what does it mean?

Could you give an example input of a time that it gives you the error?

Red Goose 21 Junior Poster

Ok so I see that p really isn't used anywhere and therefore not necessary but how does that help with the insertintoarray function? When I tried to run it without p I was missing a parameter for the function and the myarray was still corrupted.

Any ideas?

You wrote the code, what was p SUPPOSED to do? You clearly needed it for SOMETHING. The functionality exists, it's against the spirit of this forum for me to hand you the answer on a silver platter. I want you to step back and breathe. Look at what you expected p to do and why it wasn't doing it. Then, look at what you can do to apply that functionality. Just deleting the variable won't solve the problem.

Red Goose 21 Junior Poster

What do you think I should do???

I think you should examine the variable "p" in int main() and what exactly it's doing.

Or, at least, explain to me step-by-step what it's doing in your code.

Red Goose 21 Junior Poster

Ah, now we're getting somewhere.

I believe you're missing something. What is the variable "p" for and what are you using it for? Do you even need it at all or do you already have a variable that can fulfill its purpose?

Red Goose 21 Junior Poster

Please use the CODE tags when posting code, it makes it much easier to read.

Also, please post your whole code.

Red Goose 21 Junior Poster

Show us what you have so far.

Red Goose 21 Junior Poster

Hint: You can check the validity of the board by the sum of all the numbers within a given column or row.

Red Goose 21 Junior Poster

Most likely you're exceeding the limitation of the variable, so at some point, it's counting over to 0, and then multiplies from 0 there onward.

Not much can be done about that, except perhaps storing the number inside a container or something of the like. You're not going to find a variable type that can hold a number as big as you're trying to make.

Red Goose 21 Junior Poster

setprecision affects the output stream, not the variable, therefore, it will continue to display the precision until you change it.

Example:

#include <iostream>
#include <iomanip>

using std::cout;
using std::setprecision;

int main()
{
 float x = 5.12384;

 cout << "Variable = " << x << "\n";
 cout << "Precision 2 = " << setprecision(2) << x << " " << x; //note that the precision continues.
 cout << "\nPrecision 3 = " << setprecision(3) << x;
 cout << "\nShowing no precision = " << setprecision(0) << x << "\n";
 return 0;
}