[QUOTE=ZeekyHBomb;23204130]You could use a std::vector instead of an array. And you could probably score some points from the teacher when you create the menu programatically by finding the largest entry (the biggest theItem.size), adding 1 to that number then looping through each menuItemType (hint: for-loop), outputting the current number, theItem, largestEntry minus theItem.size() times a '-' and then thePrice.
To your actual problem: Use a std::list to store all valid choices, then in printCheck, you again use a loop to list all stuff the customer ordered and add up all prices. Finally, you multiply rateOfTax to the accumulated price and voilá you've got the tax.[/QUOTE]
maybe I didnt understand you fully(imanidiot) but in the problem it says to use an array.
EDIT:
Also what about this instead as that wasant working before, but lol this isnt working either
[CODE]
finished [/CODE]
I'd say std::vector and std::list are arrays. Are you certain that your teacher does not want you to use these?
I talked to him and he showed a couple examples, they were simple arrays like mine, no vectors or lists
That doesn't mean you should/can not use those, right?
If you must, then use a boolean-array, like
bool stuffOrdered[8];
initialize all to false and then do
[cpp]if(stuffOrdered[answer])
std::cout << "You already have this item." << std::endl;
else
stuffOrdered[answer] = true;[/cpp]
You can also easily adapt this for this other thing I read on the bookpage you sent, about being able to order multiple stuff on once thing. In this case you just use an int-array, initialize to 0 and increment the stuff the client orders.
[QUOTE=ZeekyHBomb;23205387]That doesn't mean you should/can not use those, right?
If you must, then use a boolean-array, like
bool stuffOrdered[8];
initialize all to false and then do
You can also easily adapt this for this other thing I read on the bookpage you sent, about being able to order multiple stuff on once thing. In this case you just use an int-array, initialize to 0 and increment the stuff the client orders.[/QUOTE]
Thanks, I dont care about the customers ordering more than one of an item, theyll get one and be happy!
I added your code, but the program opens up but then immediatly crashes, debugger says its a successful build, starts it up, shows the menu but then crashes, heres my full code
[CODE]finished[/CODE]
answer is not initialized.
[QUOTE=ZeekyHBomb;23206149]answer is not initialized.[/QUOTE]
hey i got this,
[CODE]finished} [/CODE]
yea i know i used a dreaded goto, sue me. is that right? and if so, how would i display the orders now?
and thanks for all your help, you deserve a medal
[QUOTE=shemer77;23206631]hey i got this,
[CODE]cout << "Whaddya have today? Pick a number " <<endl;
bool stuffordered[8] = {0};
int answer = 0;
top:
cin >> answer;
if (answer >=7)
{
stuffordered[answer] = true;
}
else
{
goto top;
}
} [/CODE]
yea i know i used a dreaded goto, sue me. is that right? and if so, how would i display the orders now?
and thanks for all your help, you deserve a medal[/QUOTE]
[cpp]cout << "Whaddya have today?"
bool stuffordered[8] = {0};
int answer = 0;
do
{
cout << "Pick a number " <<endl;
cin >> answer;
} while ( answer >= 7 );
stuffordered[answer] = true;
[/cpp]
I'd prefer this to the goto :3
[QUOTE=shemer77;23204743]maybe I didnt understand you fully(imanidiot) but in the problem it says to use an array.
EDIT:
Also what about this instead as that wasant working before, but lol this isnt working either
[CODE]
cout << "Whaddya have today? Pick a number " <<endl;
int answer;
for(answer = 0; answer < 7; answer++)
{ cin >> menuList[answer];
if(menuList[answer] = 8)
break;
}
} [/CODE][/QUOTE]
You don't need the last two lines in the For statement. That is what the "answer < 7" bit does.
[QUOTE=shemer77;23206631]hey i got this,
[CODE]cout << "Whaddya have today? Pick a number " <<endl;
bool stuffordered[8] = {0};
int answer = 0;
top:
cin >> answer;
if (answer >=7)
{
stuffordered[answer] = true;
}
else
{
goto top;
}
} [/CODE]
yea i know i used a dreaded goto, sue me. is that right? and if so, how would i display the orders now?
and thanks for all your help, you deserve a medal[/QUOTE]
Well, think about what you're storing in stuffordered; write it side-by-side to the menuList array and it should become apparent to you.
[QUOTE=esalaka;23184447]Until the packet is received at the other end?
I dunno, does TCP send confirmations upon receiving packets?[/QUOTE]
Found out that it will block if there is a pending send operation. So like if you call it twice in a row with 5mb of data. The second call will block until the first send has been received by the client.
This is good, so I can setup a thread that sends data in a list based on priority and size.
[QUOTE=high;23213352]The second call will block until the first send has been received by the client.[/QUOTE]
No, just until it's been transmitted. The data from the first send() may still be in-transit when the second send() call returns.
[QUOTE=high;23182361]Is it possible to have winsocks "send" function block until the packet is received?[/QUOTE]
TCP is a stream-oriented protocol. There's no guarantee that the data you pass to a single send() call will correspond to exactly one packet one the network. The system may put some of the data into one packet and the rest into another packet, and it may combine the data from multiple send() calls together into a larger packet (see [url=http://en.wikipedia.org/wiki/Nagle's_algorithm]Nagle's algorithm[/url]). So it doesn't make much sense to talk about "the packet" being received when you're using TCP.
The remote host does send back information about how much data has been received so far, and it's used by the TCP implementation (in the kernel) to detect when packets have been lost and need to be retransmitted, but AFAIK that information isn't made available to the application, because it's not part of the stream abstraction that TCP provides. Anyway, that only indicates whether the machine has received the data, not whether the application has successfully processed it. If you really need to know when the other end has processed the data you sent it, your best bet is to send back application-level acknowledgements within the TCP stream.
hey guys, just wanted you to know chad mobile will never be a problem for you again. keep doing what you do best
[QUOTE=Big Blue;23223577]hey guys, just wanted you to know chad mobile will never be a problem for you again. keep doing what you do best[/QUOTE]
[media]http://www.youtube.com/watch?v=3GwjfUFyY6M[/media]
I can't seem to find a tutorial on this. How do I make a button in SFML?
I know how to make something happen when you press a key, but I want to be able to make something happen when the user presses an image.
[QUOTE=slayer20;23224593]I can't seem to find a tutorial on this. How do I make a button in SFML?
I know how to make something happen when you press a key, but I want to be able to make something happen when the user presses an image.[/QUOTE]
SFML does not provide a GUI library. There probably exists many simple GUI libraries using SFML back-ends though, and you can use any GUI system which happens to support an OpenGL back-end.
Of course, you could also make your own. Leaving abstractions aside, it's as simple as checking the mouse position when a mouse button is pressed and comparing that to the bounding box of your image.
So not only do I have to have SFML, I have to find another thing to make buttons?
Programming ;__;
If you want everything to be given to you on a platter like that, you'd be better off with C#. Just sayin'
[QUOTE=slayer20;23225777]So not only do I have to have SFML, I have to find another thing to make buttons?
Programming ;__;[/QUOTE]
Simple button:
Wait for a mouse click, check if the mouse click's position is inside of the bounds defined by your button, if it is do the defined work. If it isn't, do nothing.
Its a really simple concept, especially cause I think SFML provides rectangle a rectangle collision function (?) that you could use to check if your mouse click was within the defined bounds.
In programming you'll often find that certain things aren't going to be predefined for you, so keep your mind dynamic, always open to new ideas and new ways of doing things. Sure, sometimes the method you come up with wont be the most efficient or fantastic way of doing things, but each time you come up with something new is another learning experience, pushing your mind to new limits of creativity. This is probably the best part of programming, is trying hard to make your dreams into reality, and finding that after all your effort, it actually worked. :D
[QUOTE=slayer20;23225777]So not only do I have to have SFML, I have to find another thing to make buttons?
Programming ;__;[/QUOTE]
Just draw a rectangle with some text on it and if the mouse is clicked then check if it's within the boundaries of the button rectangle. Easy.
[QUOTE=Wyzard;23220513]No, just until it's been transmitted. The data from the first send() may still be in-transit when the second send() call returns.
TCP is a stream-oriented protocol. There's no guarantee that the data you pass to a single send() call will correspond to exactly one packet one the network. The system may put some of the data into one packet and the rest into another packet, and it may combine the data from multiple send() calls together into a larger packet (see [url=http://en.wikipedia.org/wiki/Nagle's_algorithm]Nagle's algorithm[/url]). So it doesn't make much sense to talk about "the packet" being received when you're using TCP.
The remote host does send back information about how much data has been received so far, and it's used by the TCP implementation (in the kernel) to detect when packets have been lost and need to be retransmitted, but AFAIK that information isn't made available to the application, because it's not part of the stream abstraction that TCP provides. Anyway, that only indicates whether the machine has received the data, not whether the application has successfully processed it. If you really need to know when the other end has processed the data you sent it, your best bet is to send back application-level acknowledgements within the TCP stream.[/QUOTE]
Well the second send call is returning after the server has received it :x. In fact it isn't returning until the original and the one it is sending is received.
But anyways, I really just wanted to know if it blocked at all. Because I don't have to worry about calling it too much or too fast in a loop.
[QUOTE=slayer20;23225777]So not only do I have to have SFML, I have to find another thing to make buttons?
Programming ;__;[/QUOTE]
this hobby/profession obviously isn't for you.
You don't have to use SFML, you can do it all yourself if you want.
[QUOTE=slayer20;23225777]So not only do I have to have SFML, I have to find another thing to make buttons?
Programming ;__;[/QUOTE]
SFML is a media, not a GUI framework.
Maybe you should choose another, more fitting framework for whatever you wanna do.
[QUOTE=high;23226647]But anyways, I really just wanted to know if it blocked at all. Because I don't have to worry about calling it too much or too fast in a loop.[/QUOTE]
When you call send(), your data is copied into a buffer in the kernel to be transmitted later -- waiting for a short delay as per Nagle's algorithm, and/or waiting for the remote host's [url=http://en.wikipedia.org/wiki/Transmission_Control_Protocol#Flow_control]receivewindow[/url] to indicate that it's OK to send more data. The size of that buffer is finite, and when it doesn't have room for the new data you're trying to send(), the send() call blocks until space becomes available in the buffer. Averaged out over multiple calls, the rate at which you can send() is limited to the available network bandwidth.
[editline]10:52AM[/editline]
You'd mentioned sending data in a certain order based on priority and size. Keep in mind that while you're blocked on a send() call, a smaller or higher-priority item might come along that ought to be sent next, but you've already committed to sending something else and your thread is just waiting for kernel buffer space to send it. You can end up sending items in sub-optimal order.
You might consider using something like select() or poll() to wait until it's possible to send more data without blocking, and [i]then[/i] determine what item needs to be sent, right at the time when it'll actually be transmitted (or at least queued in the kernel to be transmitted very soon).
[QUOTE=Wyzard;23228970]When you call send(), your data is copied into a buffer in the kernel to be transmitted later -- waiting for a short delay as per Nagle's algorithm, and/or waiting for the remote host's [url=http://en.wikipedia.org/wiki/Transmission_Control_Protocol#Flow_control]receivewindow[/url] to indicate that it's OK to send more data. The size of that buffer is finite, and when it doesn't have room for the new data you're trying to send(), the send() call blocks until space becomes available in the buffer. Averaged out over multiple calls, the rate at which you can send() is limited to the available network bandwidth.
[editline]10:52AM[/editline]
You'd mentioned sending data in a certain order based on priority and size. Keep in mind that while you're blocked on a send() call, a smaller or higher-priority item might come along that ought to be sent next, but you've already committed to sending something else and your thread is just waiting for kernel buffer space to send it. You can end up sending items in sub-optimal order.
You might consider using something like select() or poll() to wait until it's possible to send more data without blocking, and [i]then[/i] determine what item needs to be sent, right at the time when it'll actually be transmitted (or at least queued in the kernel to be transmitted very soon).[/QUOTE]
So then why doesn't it block when I call send with a 50mb buffer. But it does when I call send with a 1 byte buffer after the 50mb?
Argh, I'm in trouble with a small C# game..
I've got this form :
[img]http://dl.dropbox.com/u/5502511/Dev/TG_1.png[/img]
[img]http://dl.dropbox.com/u/5502511/Dev/TG_2.png[/img]
There's a timer (game_Timer) and a statusstrip (stats_StatusStrip)
Basically, a timer fills it with a letter every 800ms, and typing this letter should make it disappear. Of course, the letter does not disappears.
Form1.cs
[cpp]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TypingGame
{
public partial class Main_Form : Form
{
Random random = new Random();
Stats stats = new Stats();
public Main_Form()
{
InitializeComponent();
}
private void game_Timer_Tick(object sender, EventArgs e)
{
// Add a random Key to the List Box
letters_ListBox.Items.Add((Keys)random.Next(65, 90));
if (letters_ListBox.Items.Count > 7)
{
letters_ListBox.Items.Clear();
letters_ListBox.Items.Add("Game over.");
game_Timer.Stop();
start_Button.Text = "Restart";
}
}
private void Main_Form_KeyDown(object sender, KeyEventArgs e)
{
if (letters_ListBox.Items.Contains(e.KeyValue))
{
// If the key is in the list, remove it
letters_ListBox.Items.Remove(e.KeyValue);
letters_ListBox.Refresh();
if (game_Timer.Interval > 800)
game_Timer.Interval -= 25;
if (game_Timer.Interval > 400)
game_Timer.Interval -= 15;
if (game_Timer.Interval < 200)
game_Timer.Interval -= 5;
difficulty_ProgressBar.Value = 1200 - game_Timer.Interval;
stats.Update(true);
}
else
{
// You missed. No update, no points.
stats.Update(false);
}
// Update the labels.
correct_Label.Text = "Correct: " + stats.correct;
missed_Label.Text = "Missed: " + stats.missed;
total_Label.Text = "Total: " + stats.total;
accuracy_Label.Text = "Accuracy: " + stats.accuracy + "%";
// Find a way to keep track of time elapsed here
}
private void start_Button_Click(object sender, EventArgs e)
{
game_Timer.Start();
letters_ListBox.Items.Clear();
}
}
}
[/cpp]
Stats.cs
[cpp]
namespace TypingGame
{
class Stats
{
public int total = 0;
public int correct = 0;
public int missed = 0;
public int accuracy = 0;
public int totalTime = 1200;
public void Update(bool correctKey)
{
if (correctKey)
{
correct++;
}
else
{
missed++;
}
accuracy = 100 * correct / (missed + correct);
}
}
}
[/cpp]
What is wrong with it ?
Won't
[quote] letters_ListBox.Items.Remove()[/quote]
be lookng for an index number instead of the contents of the item? Like 0,1,2,3,4 etc?
Items.RemoveAt() will look for an index number. I just tried with it, still doesn't works.
I was working on a project and for debugging reasons, I put in some lines like
[cpp]cout<<"Function Running"<<endl;[/cpp]
I finished my debugging and decided to get rid of those lines. When I compile it, they're still there. It's like it's compiling an old version of my program. This is starting to really piss me off. I spent an hour trying to figure out what's wrong until I realized it's not compiling the newest version. Any thoughts?
[editline]02:57PM[/editline]
This only happens when I compile as debug, not release.
Sorry, you need to Log In to post a reply to this thread.