photoyid 26 Newbie Poster

Well, most of the page works fine except this section:
Some modifier keys have separate symbols for their left and right sides (however they cannot all be distinguished on all platforms):

key.LCTRL
key.RCTRL
key.LSHIFT
key.RSHIFT

photoyid 26 Newbie Poster

Looks like first f became doubled in my code.

Did you try to google key event wxPython? Or even Daniweb internal search.

so in actuality, I misspoke. I am using pyglet, which on some systems recognizes lshift and rshift, but not on all systems. From what I can tell.

photoyid 26 Newbie Poster

Better choice would be simple Tkinter program, which catches keyevents, and is cross platform.

from Tkinter import *

root = Tk()

def key(event):    
    frame.focus_force()
    print "pressed", repr(event.keysym)


frame = Frame(root, width=100, height=100)
frame.bind("<Key>", key)
frame.pack()
frame.focus_set()

root.mainloop()

Source: http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm

Thank you very much! That was really quite impressive!

So that worked but not for my program. I am using wxPython for the program, so it wouldn't really make so much sense to make a Tkinter frame to pick up the keys.

photoyid 26 Newbie Poster

Windows: http://docs.python.org/faq/windows.html#how-do-i-check-for-a-keypress-without-blocking
Linux etc: http://docs.python.org/library/curses.html

I appreciate that you answered the questions but I am looking at it, and I don't see what you mean....

Can you explain what you are saying a bit more?

photoyid 26 Newbie Poster

Oh, did I mention that a requirement of the code is that it works on windows, Linux and Mac?

photoyid 26 Newbie Poster

Is there a way to determine which shift key is pressed? I am writing a program that shows an image and I want the user to say which side of the screen it is showing up on....

I thought of using the mousekeys but realized that not all computers have mousekeys. Is there a way to determine it is the left shift key or the right shift key?

photoyid 26 Newbie Poster

Ya, but we were told not to use them. Have to figure it out the long way.

Oh, that sounds like a lot more fun :-)

photoyid 26 Newbie Poster

Are you aware that there are member functions in the ctime library that can help you with this. I forget exactly what they are but it would make your life a lot easier.

photoyid 26 Newbie Poster

Code works fine for me.... Have you tried compiling other code? Maybe you have a slow computer?

I did get errors from you quotes but that could just be the symbol that the code brackets use for "".

photoyid 26 Newbie Poster

If you understand the algorithm and the process then you know how to program it. Why not write out your algorithm and where exactly you get stuck (ie- write the pseudo-code out)

photoyid 26 Newbie Poster

C++ program that will implement the popular numerical procedure called Thomas Algorithm. this is my final project in the lab which i have no idea how to start off... and i am really bad at c++ because this was my first ever programming class i ever took in my life... can anyone give me like step by step description that even baby can understand?? also i looked around a lot of help and many people uses #include <iostream.h>. in my class my prof only used #include <iostream> and c math i appreciate if someone make me a beginner code for this question please....

This is what a thomas algorithm is:
http://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm

Do you know what you would need to do logically ie step by step to write this program? Or do you need help with that too.

BTW, the iostream.h vs iostream is a stylistic thing which was inherited from C. The C style was to use iostream.h, in C++ it isn't necessary.

photoyid 26 Newbie Poster

Why don't you play with the numbers as a string and then convert them back to an int or double.

photoyid 26 Newbie Poster

I am not an expert but there is a logical flaw. You use the do...while loop when you want the thing to loop. By adding in a break whether or not it is between 1-5 you defeat the purpose of a loop. you could do the same code with just an if statement.

Much simpler to write it like this.

int a;
	cout << "Please enter the number between 1-5: ";
	cin >> a;   // ask user to enter value btw 1-5

		if(a>=1 && a<=5)
            cout << "Your number was " << a << endl;

If you need the code to return to the beginning if the entry is not between 1-5

int a;
	do{
                cout << "Please enter the number between 1-5: ";
	        cin >> a;   // ask user to enter value btw 1-5
        }while (a<1||a>5);
		if(a>=1 && a<=5)
            cout << "Your number was " << a << endl;
photoyid 26 Newbie Poster

You have a logic error in your code. Remember your logic tables ab = a'+b' meaning. Also you switched the terms

if (c != b && d != a){
          cout << "Incorrect Username/Password Combintation \n";
          }

should be

if (c != a || d != b){
          cout << "Incorrect Username/Password Combintation \n";
          }

Think about it like this. If you asked for both of them not to be equal to the proper values, then if the username is correct but the password is incorrect the program would continue, but if you say that when one is true (c!=a or d!=b) then the whole statement is true it will work.

Also you forgot an = sign:

if (c == b && d = a){
          cout << "What would you like to do";

should be

if (c == b && d == a){
          cout << "What would you like to do";
photoyid 26 Newbie Poster

First of all a good attempt to write this code. Congrats!

Just a few comments-
1) Isn't the minimum balance a constant meaning that it is something that you set not that the user enters?
2) I think you forgot to deal with the 5 percent case. Why not assign a variable for the interest rate and have an if statement decide which number to set it at
Ex-

if (balance <= minbal + 5000){
intrstrt = 5%;
}
else if (balance > 5000 + minbal){
intrstrt = 3%;
}

etc.

If you give some more details that would be great.

photoyid 26 Newbie Poster

28-31

void setY(int n)
           {            
                    x = n;
           }

This should be

void setY(int n)
           {            
                    y = n;
           }

Please check for more errors.

Thank you very much, that fixed the issue. I always make one careless error like this. Anyone have any advice on how to avoid careless errors?

photoyid 26 Newbie Poster

So I am working on a faux graphics program for class. The current part that I am working on is to determine just from top left and bottom right corners what the coordinates should be. I believe my logic is good but it seems to be setting it as tl(3,1) tr 3,1 bl 5,1 br 5,1.
I don't see what I am doing wrong. If anyone can see, I would greatly appreciate it. It has to be written in this style because it needs to be expanded tremendously.

#include <iostream>
using namespace std;

class point{
    private:
        int x,y;
    public:
        point(){
            x = 0;
            y = 1;
        }
        void print(){
            cout<<x<<","<<y<<endl;
        }
        void set (int u,int v){
            x=u;
            y=v;
        }
        int getX(){
            return x;
        }
        int getY(){
            return y;
        }
        void setX(int n){
            x = n;
        }
        void setY(int n){
            x = n;
        }
};


class rectangle{
    private:
        point tl,tr,bl,br;
    public:
        rectangle();
        rectangle(point top_l, point bot_r);
        void print();
        void set(point top_l, point bot_r);
        point getTL();
        point getTR();
        point getBL();
        point getBR();
};

int main()
{
    point topleft;
    point bottomright;
    topleft.set(7,3);
    bottomright.set(2,5);

    rectangle first_rectangle(topleft,bottomright);


    first_rectangle.print();
}
rectangle::rectangle(){
    tl.setX(0);
    tl.setY(0);
    tr.setX(0);
    tr.setY(0);
    bl.setX(0);
    bl.setY(0);
    br.setX(0);
    br.setY(0);
}
rectangle::rectangle(point top_l, point bot_r){
    tl.setX(top_l.getX());
    tl.setY(top_l.getY());
    tr.setX(bot_r.getX());
    tr.setY(top_l.getY());
    bl.setX(top_l.getX());
    bl.setY(bot_r.getY());
    br.setX(bot_r.getX());
    br.setY(bot_r.getY());
}
void rectangle::print(){
    cout<<"The top left corner is: "<<tl.getX()<<","<<tl.getY()<<"."<<endl;
    cout<<"The top right corner is: "<<tr.getX()<<","<<tr.getY()<<"."<<endl;
    cout<<"The bottom left corner is: "<<bl.getX()<<","<<bl.getY()<<"."<<endl;
    cout<<"The bottom right corner is: "<<br.getX()<<","<<br.getY()<<"."<<endl;
}
void rectangle::set(point top_l, point bot_r){
    tl.setX(top_l.getX());
    tl.setY(top_l.getY());
    tr.setX(bot_r.getX());
    tr.setY(top_l.getY());
    bl.setX(top_l.getX());
    bl.setY(bot_r.getY());
    br.setX(bot_r.getX());
    br.setY(bot_r.getY());
}
Ancient Dragon commented: Nice eye-catching title :) +26
photoyid 26 Newbie Poster

Try typing in:

int main()

instead of main().

Also most people write that code a bit differently.

#include<iostream>
using namespace std;

int main(){
cout<<"Hello World"<<endl;
}

This gets rid of the need to use std before all of those calls.

photoyid 26 Newbie Poster

Wow! thanks. I can't believe I hadn't tried that....

photoyid 26 Newbie Poster
#include<iostream>
using namespace std;

class point{
    private:
        double x,y;
    public:
        double getX();
        double getY();
        void set(double c, double d);
};

class polygon{
    private:
        string color;
    public:
        void setc(string color1){
            color = color1;
        }
        void print(){
            cout<<color;
        }
        string getColor(){
            return color;
        }
};

class triangle: public polygon{
    private:
        point v1,v2,v3;
    public:
        void set(point o, point t, point th){
            v1.set(o.getX(),o.getY());
            v2.set(t.getX(),t.getY());
            v3.set(th.getX(),th.getY());
        }
};


int main(){
    point a,b,c;
    triangle t;
    a.set(1.2,3.4);
    b.set(234.4,543.23);
    c.set(34,31);
    t.set(a,b,c);
    t.setc('red');

}
double point::getX(){
    return x;
}
double point::getY(){
    return y;
}

void point::set(double c, double d){
    x = c;
    y=d;
}

We were learning c++ derivatives yesterday and the professor came up with an example (off the top of his head which is why it doesn't make perfect sense to do it this way). He wanted us to set the color of the triangle using polygon where triangle is a devative function of polygon. My compiler is giving me an error message.

f\Desktop\C++\polygon.cpp|47|warning: multi-character character constant|
\Desktop\C++\polygon.cpp||In function `int main()':|
\Desktop\C++\polygon.cpp|47|error: invalid conversion from `int' to `const char*'|
\Desktop\C++\polygon.cpp|47|error: initializing argument 1 of `std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]'|
||=== Build finished: 2 errors, 1 warnings ===|

Any help would be appreciated....