yea just put it in main, at the start like a local variable. Not in any functions and not in any loops. that way it will never seed twice.
------------------
edit: on another note I did the bunny exercise in java yesterday because I was bored and wanted to see how it would go... took me 24 hours to get around an iterator problem with my arraylist. but apart from that runs fine.... Do I win?
I'm doing the bunnie excersice, i'm up to the part where I have to make it run in real time. I was wondering how do I do that, and also the part where if someone types 'k', it kills half the bunnies. I wanted to use cin, but I don't think that will work since, it pauses the screen.
I dunno about making it run in "real time" but what you could do is put in a 1 or 2 second pause between each turn. That way you wouldn't end up with 1000 bunnies in a blink of an eye.
#include<iostream>
#include<sstream>
#include<string>
#include<math.h>
usingnamespace std;
int input()
{string temp;
int n;
getline(cin,temp);
stringstream(temp) >> n;
return n;
}
void max(int person[],int i)
{ int x=0;
for ( i=1;i<=9;i++)
{
x = (person[x] > person[i]) ? x : i;
}
cout << "person " << x+1 << " ate " << person[x] << " pancakes, that is the highest amount\n";
}
void min(int person[],int i)
{ int x=0;
for ( i=1;i<=9;i++)
{
x = (person[x] < person[i]) ? x : i;
}
cout << "person " << x+1 << " ate " << person[x] << " pancakes, that is the lowest amount\n";
}
int main()
{// opens main
int person[10];
int i; // counter for the people
cout << "please enter how many pancakes each person ate\n";
for (i=0;i<=9;i++)
{ // opens the for loop to insert pancake quantities
cout << "how many did person " << i+1 <<" eat?\n";
person[i]=input();
} // closes the for loop to insert pancake quantities
max(person, i);
min(person, i);
cin.get();
return 0;
}// closes main
Hi, new user here (did a Google search for C++ exercises :-) I have a question about the graduation question:
I'm wondering what would be the best way in this case to generate the rabbits? I have had two thoughts so far. Bear in mind I am a beginner to programming concepts, in that I have never put my knowledge to practice but have done an amount of reading.
So I had two thoughts of how it could be done: First, would be to use the new and delete commands to make new Bunny objects and remove them as and when they are needed. This solution bothers me because I am not familiar with the repercussions or requirements to make this work, but it does seem to offer the most amount of flexibility.
My second thought, was that since the docs state that 1000 bunnies is the 'limit', is to make 1000 bunny objects and give them an alive/dead state, so born bunnies are really just existing 'dead' bunnies which have their alive state switched, and their stats modified to become 'new' bunnies.
I was hoping someone could offer some thoughts or suggest other ways of tackling this problem, thanks :-)
merkaba48, it's actually already decided what you should use. In the requirements, it mentions that you should use a linked list. C++ provides a standard stl class for lists call std::list but this is a double-linked list. That's fine but it's up to you if you want to create your own for fun or simply use the double-linked list.
http://richardbowles.tripod.com/cpp/linklist/linklist.htm - if you want to create your own linked list. This also explains what a linked list is. If you understand pointers, this concept is easy.
http://cplusplus.com/reference/stl/list/ - if you want to use std::list.
You don't make sense... You can't qualify advice as false, it has no true/false value. "Use pdcurses on windows or ncurses or UNIX/Linux" isn't a true/false statement. It's advice.
Alright, it's not false. It's just pointless. There's no reason to prefer either on either platform.
It's the equivalent of "use your watch on your right wrist when north of the equator, but on your left when south of it".
There's no reason to prefer either on either platform.
My mistake, I thought PDCurses only worked on windows, and NCurses only worked on *NIX. I just did a Google search and apparently PDCurses works on both, and NCurses works on windows through Cygwin. So you can just choose one.