Unofficial Programming Thread

Post » Thu Sep 23, 2010 10:22 pm

Do you use Visual Studio as your IDE? If so just put ina breakpoint and step through the code and check all your variables. Though I really do not know much C++ your for loop seems like it would go on forever and it surrounds that dowhile. Again I don't really know C++ so I could be wrong or it could be by design but I would look into it.

I'm using Dev C++.

@Orzorn: Have you removed anything from that code? I wouldn't expect that to compile. There is a for loop there that doesn't have a closing } symbol and doesn't do anything anyway, and your main function doesn't have a closing } symbol either.

Yes, it did run.

Also, I'm pretty sure everything had a closing brace. Count the braces, there are 4 on top and 4 on bottom.
User avatar
Ross
 
Posts: 3384
Joined: Thu Aug 10, 2006 7:22 pm

Post » Thu Sep 23, 2010 4:41 pm

Now, when I type 'q' at any time, its SUPPOSED to break the loop, then, because after the loop the program reads that dmas = q, then it doesn't re-enter the loop, and then the program closes.

You are breaking out of the switch block, not the for loop.


Also, you are including C headers, when using C++ prefer over
User avatar
vicki kitterman
 
Posts: 3494
Joined: Mon Aug 07, 2006 11:58 am

Post » Thu Sep 23, 2010 9:46 pm

Also, you are including C headers, when using C++ prefer over

I tried and the compiler gave me an error.

Edit:
Alright here's what I've got now:
#include #include #include #include #include using namespace std;int main(int argc, char *argv[]){    float x = 0;    float y = 0;    char dmas;    do{    cout<<"Divide (/), multiply (*), add (+), or subtract (-)? Press q to quit.\n\n";    cin>> dmas;        switch (dmas)    {           case '/': cout<<"\nInput a number to be divided.\n\n";                   cin>> x;                   cout<<"\nInput a number to divide by.\n\n";                   cin>> y;                   if (y == 0){                   cout<<"\nYou can not divide by zero.";                   y = 1;}                   cout<<"\n" << x / y << "\n\n";                break;                           case '*': cout<<"\nInput a number to be multiplied.\n\n";                   cin>> x;                   cout<<"\nInput a number to multiply by.\n\n";                   cin>> y;                   cout<<"\n" << x * y << "\n\n";                break;                           case '+': cout<<"\nInput a number to be added.\n\n";                   cin>> x;                   cout<<"Input a number to add.\n\n";                   cin>> y;                   cout<<"\n" << x + y << "\n\n";                break;                           case '-': cout<<"\nInput a number to be subtracted from.\n\n";                   cin>> x;                   cout<<"Input a number to subract.\n\n";                   cin>> y;                   cout<<"\n" << x - y << "\n\n";                break;                           case 'q':break;                         default: cout<<"\nThat isn't a valid entry.\n\n";                    break;}}while (dmas != 'q');return 0;}


I can quit the program, but ONLY at the beginning of it (or when it loops back around). If I enter a choice (such as '/'), THEN try Q, I get stuck in an infinite loop and I am forced to terminate it myself. Is there a way to let me terminate while I'm INSIDE of the switch entries?
User avatar
Tessa Mullins
 
Posts: 3354
Joined: Mon Oct 22, 2007 5:17 am

Post » Thu Sep 23, 2010 6:21 pm

You can define a separate boolean variable as the exit condition..
User avatar
Nitol Ahmed
 
Posts: 3321
Joined: Thu May 03, 2007 7:35 am

Post » Thu Sep 23, 2010 12:11 pm

I tried and the compiler gave me an error.

My bad, it was you need. Well, you don't. The only include you need is .
User avatar
Jonny
 
Posts: 3508
Joined: Wed Jul 18, 2007 9:04 am

Post » Thu Sep 23, 2010 5:18 pm

I can quit the program, but ONLY at the beginning of it (or when it loops back around). If I enter a choice (such as '/'), THEN try Q, I get stuck in an infinite loop and I am forced to terminate it myself. Is there a way to let me terminate while I'm INSIDE of the switch entries?


It could be to do with the input stream. Try putting cin >> ws; just before cin>> dmas;
User avatar
Alyesha Neufeld
 
Posts: 3421
Joined: Fri Jan 19, 2007 10:45 am

Post » Thu Sep 23, 2010 10:46 pm

I can quit the program, but ONLY at the beginning of it (or when it loops back around). If I enter a choice (such as '/'), THEN try Q, I get stuck in an infinite loop and I am forced to terminate it myself. Is there a way to let me terminate while I'm INSIDE of the switch entries?

I can't reproduce that with your code in Visual Studio. However, the code does not check for a capital Q. It still just prints out not valid and goes back to the beginning though.

However, if you mean typing "/Q" as the option, then what you describe seems to happen. That got me curious..

You are reading a single character with cin >> dmas. When you enter "/Q", it gets the slash and goes into your '/' case. However, you have another set of commands there that read input, so the Q ends up there and the execution passes both cin's because they don't understand characters. Your exit condition still checks for dmas and that happens to be '/' letting it continue, but the next cin against passes right through.

Add line cin.ignore(); right after cin >> dmas. It flushes the rest of the characters out of the buffer as you only seem to be interested in the first character. That should fix it the easiest.
User avatar
Cat Haines
 
Posts: 3385
Joined: Fri Oct 27, 2006 9:27 am

Post » Thu Sep 23, 2010 9:20 am

Am I allowed to advertise here? I don't suppose there are any Python or C++ developers interested in a project related to the games we all know and love (TES / FO3)? :rolleyes:
User avatar
Laura-Lee Gerwing
 
Posts: 3363
Joined: Fri Jan 12, 2007 12:46 am

Post » Thu Sep 23, 2010 4:02 pm

I need help making a guessing game work with a random number <10
So please help if you can.
Spoiler
[Block3]'is for guessing game    Prompt "Guess which number i'm thinking of."; guessnumber        let number = int(rdn (number < 10))''' Need help in this line!        select case number            case guessnumber = number                Notice "Correct!"                    goto [Block2]            case else                notice "Wrong"[try$]           Prompt "Try again?"; try$ ' Try again? $ variable                    select case lower$(try$)                        case "yes"                            goto [BLock3]                        case "no"                            end                        case else                            Notice "What?"                            goto [try$]                    end select        end select


User avatar
Miragel Ginza
 
Posts: 3502
Joined: Thu Dec 21, 2006 6:19 am

Post » Thu Sep 23, 2010 11:37 pm

Am I allowed to advertise here? I don't suppose there are any Python or C++ developers interested in a project related to the games we all know and love (TES / FO3)? :rolleyes:

You can ask for project help here thats fine. Unfortunately I don't know either of those languages so I won't be of much help. I guess I could do documentation for it perhaps depending on project scope and complexity.
User avatar
StunnaLiike FiiFii
 
Posts: 3373
Joined: Tue Oct 31, 2006 2:30 am

Post » Thu Sep 23, 2010 9:09 pm

Am I allowed to advertise here? I don't suppose there are any Python or C++ developers interested in a project related to the games we all know and love (TES / FO3)? :rolleyes:

Can you give me some details? I'm not bad with either Python or C++.
User avatar
Andy durkan
 
Posts: 3459
Joined: Fri Aug 03, 2007 3:05 pm

Post » Thu Sep 23, 2010 10:41 pm

So since I am heading back to school soon I need to keep a list of things that I must take or do and I have decided to write a small program for this. I will store each list as an XML file and allow for the user to input their own filename. I am writing it in C# using .NET 3.5 if anyone would like to help out. It won't be a very large project and probably will be completed quickly but even so I thought I would see who was interested.
User avatar
JR Cash
 
Posts: 3441
Joined: Tue Oct 02, 2007 12:59 pm

Post » Thu Sep 23, 2010 5:17 pm

I'm having issues with a program I'm writing in wxPython, using Python 2.6. The event happens when the program begins, and I'm short on ideas to work around this.

class main(wx.Frame):    def __init__(self, parent):...        bTestText = wx.Button(panel, label = 'test', pos = (100,100))        evt = kickBox().testText(EVT_TEXT)        self.Bind(wx.EVT_BUTTON, evt, bTestText)...class kickBox(main):    def __init__(self):        self.origin = wx.Frame.__init__(self, wx.GetApp().TopWindow, title='HTML Kickbox', size=(600,600), name = "kickBox")        self.textbox = wx.TextCtrl(self,1,style=wx.TE_MULTILINE)        self.textbox.SetEditable(False)...    def testText(self, evt):        self.textbox.AppendText("test")        print "works"...


Returns on startup:
>>>works

On a button press, it returns nothing - or in other words, doesn't work.

Any help would be appreciated. :)
User avatar
sas
 
Posts: 3435
Joined: Thu Aug 03, 2006 8:40 am

Post » Thu Sep 23, 2010 7:01 pm

Hi guys, im really getting frustrated with this so Im posting here.. What I need to do is really simple, yet I cannot do it apparently. Here is what works:

DWORD Address = 0x4000F6;

I can use Address and it works perfectly. But this is staticly bound, I want to be able to read the address from a file, then read the value from the file and store in Address. I've tried many things on lines of:

    string line;    ifstream myfile ("file.txt");    if (myfile.is_open())    {		int i = 1;		while (!myfile.eof())		{			getline (myfile, line);			if (i == 1) //first line contains the value.				Address = atoi(line.c_str());			if (i == 2) //second line ect.				blah blah blah,			i++;		}        myfile.close();    }


But that doesnt work. How should the value in the text file be formatted, like "0x4000F6" or "4000F6"? Im not concerned about how well done or efficient my code for reading the file is, I just want to get it working then I can clean it up... Thanks in advance if anyone knows. C++ can be a :swear:
User avatar
Adrian Morales
 
Posts: 3474
Joined: Fri Aug 10, 2007 3:19 am

Post » Thu Sep 23, 2010 4:57 pm

I started a VB.NET class here at school which is an intro class but I have done a wholeintro class on it before and gotten farther with C#. On Wednesday we are having a pretest to see who knows what, if we get 80% or higher the instructor said he may see about having us marked as testing out of it. Now I am not holding my breath on this but since I have worked with it before I may brush up on it tomorrow and see how well I do. I have the book but I kind of prefer the one I have at home frm my old class, and I won't be able to get it until this weekend.
User avatar
Leah
 
Posts: 3358
Joined: Wed Nov 01, 2006 3:11 pm

Post » Thu Sep 23, 2010 8:27 am

Can you give me some details? I'm not bad with either Python or C++.


That would be http://niftools.sourceforge.net. But there's a lot of hate for the Gamebryo engine around here :shrug:
User avatar
(G-yen)
 
Posts: 3385
Joined: Thu Oct 11, 2007 11:10 pm

Post » Thu Sep 23, 2010 3:57 pm

Hey I was wondering if anybody would know where I could find an internship? I've heard banks, but I'd like to be able to hit a few places and see if they'd need an intern.

I don't need specific places, just types of stores. Such as a laundromat, which has nothing to do with coding, but that's a type of store. :P
User avatar
Gracie Dugdale
 
Posts: 3397
Joined: Wed Jun 14, 2006 11:02 pm

Post » Thu Sep 23, 2010 8:09 pm

Is anyone any good with programming in TI Basic? I want to write a small program for my statistics class but for some reason some of my code never runs and I can't figure out how to make it run. I have an idea how but I want to not have duplicate lines so I am using Goto and Lbl stuff to bounce around but then I need some decision logic but not sure where to put it or how to use it. If anyone ever programmed for this calculator let me know so I can post the code for troubleshooting.

Its more annoying to do since the TI-83+ that I have (most basic one) does not come with the USB cable for easy editing and tansferring of programs.
User avatar
Vincent Joe
 
Posts: 3370
Joined: Wed Sep 26, 2007 1:13 pm

Post » Thu Sep 23, 2010 10:08 am

DarkOneVenzar I have a question!

In C#, how do I make a random integer and apply it into this set of code...
Also, if you could tell me if this is a good way to write something like the following in C#. I know you're still learning but any constructive criticism would be appreciated.
Spoiler
namespace GuessingGame{	class MainGame // TODO Make different functions for the many things I've done in the class	{		public static void Main()		{			// Declarations of variables			string name; /* The name of the user */			string guessednumber; /* The number inputted by the user */			string truenumber = "7"; // TODO Make this a random integer			string playagain;			string sure;						// Console I.O.			/* This asks for the users name and what number they are guessing */			Console.Out.WriteLine("Please enter your name...");			name = Console.In.ReadLine();			Console.Out.WriteLine("Hello {0}",name);						Console.Out.WriteLine("Now enter a number to guess...");			guessednumber = Console.In.ReadLine();						// Decision Making			if (guessednumber == truenumber) /* The IF determines whether the guessed number is equal to the true number */			{				Console.Out.WriteLine("Correct!");				Console.Out.WriteLine("Would you like to play again?");				playagain = Console.In.ReadLine();								if (playagain == "yes") /* This IF determines whether the user wants to play again */				{					GuessingGame.MainGame.Main();				}				else if (playagain == "no")				{					Console.Out.WriteLine("Are you sure?");					sure = Console.In.ReadLine();										if (sure == "yes") /* This determines whether the user us sure they want to re-play */					{					Console.ReadKey();						}				}								}			else 			{				Console.Out.WriteLine("Wrong!");				Console.Out.WriteLine("Would you like to play again?");				playagain = Console.In.ReadLine();				if (playagain == "yes")				{					GuessingGame.MainGame.Main();				}							}		}	}

User avatar
Jennifer May
 
Posts: 3376
Joined: Thu Aug 16, 2007 3:51 pm

Post » Thu Sep 23, 2010 4:37 pm

DarkOneVenzar I have a question!

In C#, how do I make a random integer and apply it into this set of code...

I know I am the wrong person, but: http://msdn.microsoft.com/en-us/library/system.random.aspx
User avatar
Tikarma Vodicka-McPherson
 
Posts: 3426
Joined: Fri Feb 02, 2007 9:15 am

Post » Thu Sep 23, 2010 12:00 pm

DarkOneVenzar I have a question!

In C#, how do I make a random integer and apply it into this set of code...
Also, if you could tell me if this is a good way to write something like the following in C#. I know you're still learning but any constructive criticism would be appreciated.
Spoiler
namespace GuessingGame{	class MainGame // TODO Make different functions for the many things I've done in the class	{		public static void Main()		{			// Declarations of variables			string name; /* The name of the user */			string guessednumber; /* The number inputted by the user */			string truenumber = "7"; // TODO Make this a random integer			string playagain;			string sure;						// Console I.O.			/* This asks for the users name and what number they are guessing */			Console.Out.WriteLine("Please enter your name...");			name = Console.In.ReadLine();			Console.Out.WriteLine("Hello {0}",name);						Console.Out.WriteLine("Now enter a number to guess...");			guessednumber = Console.In.ReadLine();						// Decision Making			if (guessednumber == truenumber) /* The IF determines whether the guessed number is equal to the true number */			{				Console.Out.WriteLine("Correct!");				Console.Out.WriteLine("Would you like to play again?");				playagain = Console.In.ReadLine();								if (playagain == "yes") /* This IF determines whether the user wants to play again */				{					GuessingGame.MainGame.Main();				}				else if (playagain == "no")				{					Console.Out.WriteLine("Are you sure?");					sure = Console.In.ReadLine();										if (sure == "yes") /* This determines whether the user us sure they want to re-play */					{					Console.ReadKey();						}				}								}			else 			{				Console.Out.WriteLine("Wrong!");				Console.Out.WriteLine("Would you like to play again?");				playagain = Console.In.ReadLine();				if (playagain == "yes")				{					GuessingGame.MainGame.Main();				}							}		}	}


Where did you want the random number? You would, like Yacoby said, use the System.Random class.

You would do this:
Random r = new Random();r.next(min, max);


Replace r with whatever name you want for the variable, and min/max for your range. So if you do r.Next(0, 100) it will give a random number between 0 and 100 inclusive.
User avatar
Madison Poo
 
Posts: 3414
Joined: Wed Oct 24, 2007 9:09 pm

Post » Thu Sep 23, 2010 10:21 am

Where did you want the random number? You would, like Yacoby said, use the System.Random class.

You would do this:
Random r = new Random();r.next(min, max);


Replace r with whatever name you want for the variable, and min/max for your range. So if you do r.Next(0, 100) it will give a random number between 0 and 100 inclusive.

I know where I can put it. Thank you, both of you.
Edit: Or not. I was gonna put it where I would like to make it so truenumber would be a random number. So I could do If guessednumber == truenumber and have truenumber be random between 1 and 15.

Spoiler
using System;// TODO Finish documentingnamespace GuessingGame{	class MainGame // TODO Make different functions for the many things I've done in the class	{		public static void Main()		{			// Declarations of variables			string name; /* The name of the user */			string guessednumber; /* The number inputted by the user */			Random truenumber = "7"; // TODO Make truenumber a random Integer			string playagain;			string sure;						// Console I.O.			/* This asks for the users name and what number they are guessing */			Console.Out.WriteLine("Please enter your name...");			name = Console.In.ReadLine();			Console.Out.WriteLine("Hello {0}",name);						Console.Out.WriteLine("Now enter a number to guess...");			guessednumber = Console.In.ReadLine();						// Decision Making			if (guessednumber == truenumber) /* The IF determines whether the guessed number is equal to the true number */			{				Console.Out.WriteLine("Correct!");				Console.Out.WriteLine("Would you like to play again?");				playagain = Console.In.ReadLine();								if (playagain == "yes") /* This IF determines whether the user wants to play again */				{					GuessingGame.MainGame.Main();				}				else if (playagain == "no")				{					Console.Out.WriteLine("Are you sure?");					sure = Console.In.ReadLine();										if (sure == "yes") /* This determines whether the user us sure they want to re-play */					{					Console.ReadKey();						}				}								}			else 			{				Console.Out.WriteLine("Wrong!");				Console.Out.WriteLine("Would you like to play again?");				playagain = Console.In.ReadLine();				if (playagain == "yes")				{					GuessingGame.MainGame.Main();				}							}		}	}}

User avatar
Alex Blacke
 
Posts: 3460
Joined: Sun Feb 18, 2007 10:46 pm

Post » Thu Sep 23, 2010 5:23 pm

I'm in a Java coding class, and I need to make a program that calculates how long someone has been alive, and slept from the user inputting the Birthdate, and Current Date.

The thing simplifies it with , everyone sleeps 8 hours a night, and 30 days in a month,and the regular amount of days in the year.
We use Netbeans, and it is Elearning, so I have no teacher or class to help me, it's all online.
Any ideas on the MATH part of it, I know how to make the program, I just don't understand the part on getting the final result.
User avatar
Matthew Barrows
 
Posts: 3388
Joined: Thu Jun 28, 2007 11:24 pm

Post » Thu Sep 23, 2010 1:51 pm

I know where I can put it. Thank you, both of you.
Edit: Or not. I was gonna put it where I would like to make it so truenumber would be a random number. So I could do If guessednumber == truenumber and have truenumber be random between 1 and 15.

Spoiler
using System;// TODO Finish documentingnamespace GuessingGame{	class MainGame // TODO Make different functions for the many things I've done in the class	{		public static void Main()		{			// Declarations of variables			string name; /* The name of the user */			string guessednumber; /* The number inputted by the user */			Random truenumber = "7"; // TODO Make truenumber a random Integer			string playagain;			string sure;						// Console I.O.			/* This asks for the users name and what number they are guessing */			Console.Out.WriteLine("Please enter your name...");			name = Console.In.ReadLine();			Console.Out.WriteLine("Hello {0}",name);						Console.Out.WriteLine("Now enter a number to guess...");			guessednumber = Console.In.ReadLine();						// Decision Making			if (guessednumber == truenumber) /* The IF determines whether the guessed number is equal to the true number */			{				Console.Out.WriteLine("Correct!");				Console.Out.WriteLine("Would you like to play again?");				playagain = Console.In.ReadLine();								if (playagain == "yes") /* This IF determines whether the user wants to play again */				{					GuessingGame.MainGame.Main();				}				else if (playagain == "no")				{					Console.Out.WriteLine("Are you sure?");					sure = Console.In.ReadLine();										if (sure == "yes") /* This determines whether the user us sure they want to re-play */					{					Console.ReadKey();						}				}								}			else 			{				Console.Out.WriteLine("Wrong!");				Console.Out.WriteLine("Would you like to play again?");				playagain = Console.In.ReadLine();				if (playagain == "yes")				{					GuessingGame.MainGame.Main();				}							}		}	}}


For truenumber do it like this:
Random truenumber = new Random();truenumber.Next(1, 15);


If you make guessednumber an int you can compare the values better and when you want to output them just use ToString() on the int.
User avatar
sam westover
 
Posts: 3420
Joined: Sun Jun 10, 2007 2:00 pm

Post » Thu Sep 23, 2010 10:07 pm

I'm in a Java coding class, and I need to make a program that calculates how long someone has been alive, and slept from the user inputting the Birthdate, and Current Date.

The thing simplifies it with , everyone sleeps 8 hours a night, and 30 days in a month,and the regular amount of days in the year.
We use Netbeans, and it is Elearning, so I have no teacher or class to help me, it's all online.
Any ideas on the MATH part of it, I know how to make the program, I just don't understand the part on getting the final result.

Is it enough to convert the entered Birthdate (and Current Date?) into seconds or hours, and the current date the same way? Then just subtract birth time from the current time, get the time alive, and assume that the person has slept one third of the time and has stayed awake the rest. Then convert that back to years, months, days and hours or what accuracy is required. In my mind, it's more complex having to computer years, months, days, hours etc separately...

Or, do you have take into account current time of day where the person has not been exactly asleep one third of the day, or that the user might be born at a certain minute of some day and not assumed to be born at midnight.

However, then there's summer time. You could convert the times into GMT and do the calculations in that environment. You don't need to convert back to user time since the user only seems to be interested in differences.

I can't help you with Java specifically though, but you didn't actually ask that, did you. It probably has something to do with the Calendar, Date, getTime(), and SimpleDateFormat.. getTime on Date returns milliseconds since 1970, I think.
User avatar
Kat Ives
 
Posts: 3408
Joined: Tue Aug 28, 2007 2:11 pm

PreviousNext

Return to Othor Games