SRL Archive - C/C++ Help and Tutorials

Ok super stuck here.


TheSantaMan

2010-11-30 04:53:14

So this should be way easier than i'm making it but here's what I got:

I'm trying to simulate tile walking in a basic way.

I'm trying to:
Have a starting tile and Increment it till it hits within 100 of the final destination.

I'll show what I have so far but if someone could finish it so I could see, how It should look that would be great. Mostly i'm confused about the bracket placement, and how they should be used.

#include<iostream>

//Idea for tile finding basic...


using namespace std;

int main()
{

int start = 2367, finish = 28630;

//Basic failsafe to start..

if (start = 2367) {
cout << "You are in the correct place starting script\n";
cout << "Now walking in 100+ inc. til destination";
}
else
cout << "You are not in the correct place";
for (start; start << 28730, start >> 2530, start+=25){

I wasn't sure if the way I put the integers in was correct, feel free to correct me.

Thanks!

Frement

2010-11-30 05:39:47

#include <iostream>

using namespace std;

int main() {

int start = 2367
int finish = 28630;

if (start == 2367) {
cout << "You are in the correct place starting script\n";
cout << "Now walking in 100+ inc. til destination";
} else {
cout << "You are not in the correct place";
for (start; start <= 28730; start += 25) {
//Do stuff.
}
}

}

Try that, I don't have a compiler at school so I can't try it.

TheSantaMan

2010-11-30 05:46:42

From: Frement
#include <iostream>

using namespace std;

int main() {

int start = 2367
int finish = 28630;

if (start == 2367) {
cout << "You are in the correct place starting script\n";
cout << "Now walking in 100+ inc. til destination";
} else {
cout << "You are not in the correct place";
for (start; start <= 28730; start += 25) {
//Do stuff.
}
}

}

Try that, I don't have a compiler at school so I can't try it.


Ok so I guess my confusion now; is the for loop still part of else?

Cause I want it to be separate from the else statement. I just want the else statement to say wrong place, then continue on with the for loop.

Basic Idea I had:
structure:
the failsafe
the for loop to keep going till it hits around 100 of the finishing tile
and cout for everytime it increases by 25 so I can see it increase by 25 till it hits within 100 of the finishing tile.

TheSantaMan

2010-11-30 05:53:05

I see why you did it the way you did, I'm re-making it so we'll see if it makes sense after i'm done with it.

Frement

2010-11-30 05:55:53

#include <iostream>
#include <sstream>

using namespace std;

int main() {

int start = 2367
int finish = 28630;

if (start == 2367) {
cout << "You are in the correct place starting script\n";
cout << "Now walking in 100+ inc. til destination\n";
} else {
cout << "You are not in the correct place\n";
}

for (start; start <= 28730; start += 25) {
cout << "Increasing start value by 25.\n";
stringstream out;
out << start;
string = out.str();
cout << "Current value: " << string << "\n";
}

cout << "End of program.\n";

}

Heres how that would go.

TheSantaMan

2010-11-30 06:07:06

From: Frement
#include <iostream>
#include <sstream>

using namespace std;

int main() {

int start = 2367
int finish = 28630;

if (start == 2367) {
cout << "You are in the correct place starting script\n";
cout << "Now walking in 100+ inc. til destination\n";
} else {
cout << "You are not in the correct place\n";
}

for (start; start <= 28730; start += 25) {
cout << "Increasing start value by 25.\n";
stringstream out;
out << start;
string = out.str();
cout << "Current value: " << string << "\n";
}

cout << "End of program.\n";

}

Heres how that would go.


i haven't learned
out
yet or
string = out.str()

what does this do? Sorry for the awful nooby questions.

Frement

2010-11-30 06:59:36

From: jesus45
i haven't learned
out
yet or
string = out.str()

what does this do? Sorry for the awful nooby questions.


Basically converts int to string.

EDIT: Heres a compiling console app, compiled with MSVC++ 2008 Express:
#include <iostream>
#include <sstream>

using namespace std;

int main() {

int start = 2367;
int finish = 28630;

if (start == 2367) {
cout << "You are in the correct place starting script\n";
cout << "Now walking in 100+ inc. til destination\n";
} else {
cout << "You are not in the correct place\n";
}

for (start; start <= 28730; start += 25) {
cout << "Increasing start value by 25.\n";
stringstream out;
out << start;
string str = out.str();
cout << "Current value: " << str << "\n";
}

cout << "End of program.\n";

system("pause");

}

XcanadamanX

2010-11-30 12:43:40

Frement, you dont need to use a stringstream in that situation. you can just use cout << start; to output the position.

HyperSecret

2010-11-30 13:04:27

Why not just stick to the basics….


for (start; start <= 28730; start += 25)
{
cout << "Increasing start value by 25.\n";
cout << "Current value: " << start << "\n";
}

no need for the confusion in the for loop…

Frement

2010-11-30 14:36:45

Oh, I have worked too much with Qt, and you can't qDebug() with incorrect types.