C++

Status
Not open for further replies.

Hooked

Rookie
Joined
Mar 8, 2008
Messages
51
Ephyu was helping me a bit ago and I said I was going to sleep, but wanted to make this topic real quick to remind me later to ask this question:

What function do you use to return an "if" statement, and how do you specify which "if" 'variable' (don't know the term) is correct? I hope that made sense.
 
Couldn't you set a boolean variable for a condition and have that returned... Been a long time since I've coded C++, but I'm visualizing something that works like this...

Call up the function to test the condition...
-- if condition true set variable to 1

then use the if statement to see if that variable is 1 or 0 and do what you need

I might be able to help better if you provided some more specific conditions, but for any kind of syntax, I'd have to break out my books. I switched from Comp Programming to computer networking at school and haven't coded on anything but Cisco routers in 3 years...
 
Well you can't really return an if statement, but you can return what it gets evaluated to.
bool Function()
{
return (3 == 4);
}
Something like that.
If I'm completely wrong here, feel free to explain your problem in more detail and I'll try to get back to you after work.
 
Why don't you explain the problem you're trying to solve, and I'm sure some C++ ninjas will come out of the woodwork to help you.
 
I should've clarified, I'm just beginning C++ - taking it for an AP class at the college. The instructor sucks. He told me to make a program in C++ that would say good morning if it was before 12AM and good afternoon if it was after 12AM. :/
 
Heres what I did to get the same effect:
Code:
//#include <stdio.h> if we want to use printf
#include <iostream> // for cout
#include <time.h> // for time related things


using namespace std; // so we don't have to type out "std::cout" each time

int main()
{
	time_t theTime; // time_t for storing the time as a long
	struct tm* timeinfo; // struct tm for storing the time as a usable structure

	time(&theTime); // get the current time and stick it in theTime
	timeinfo = localtime(&theTime); // convert theTime into a struct tm for local time
	int hour = timeinfo->tm_hour; // grab the hour value, which is between 0-23

	if (hour >= 12) // PM
	{
		cout << "Good evening." << endl;
		// or C style: printf("Good evening.\n");
	}
	else // AM
	{
		cout << "Good morning." << endl;
		// or C style: printf("Good morning.\n");
	}

	return 0;
}

Edit: There seems to be alot of ";"s that have randomly strayed into the code.. This seems to be a byproduct of the code formatting... Make sure you remove them if you use this code.

I'm not entirely sure if your class has went over pointers or anything of that sort, so this sample might be a bit complex, but it gets the job done.

Make sure you understand the code before you turn it in though... I've seen students who grabbed code off the internet that got asked by their instructors what certain parts did and they got in alot of trouble when they didn't have the answers. :x
 
I'd rather make my own code...the only thing I permit myself to cheat on is math (I use quickmath.com to factor quickly, etc. :P), everything else I do on my own. But C++ is so hard... :(

Can anyone recommend texts that aren't for any programming language, but to just help me get my head around the basic aspects of coding? Because I am so confused right now :cry:
 
I only know a little bit about coding, but I have come to learn that it is pretty much just a matter of learning all of the basic commands you can, and how they work, and then it is just strait up logic from there. That goes for pretty much any programing language. Set up variables and use logic to get a task done from there. I'm no pro at coding, so that is about all I can do to help you :D
 
Ask Questions, Ask Questions, Ask Questions.

I know C pretty well. C++, well I haven't done extensive OOP but I'm alright-proficient with it (OOP). The sooner you get those things you know out of your mind, the better you'll be. Also try to get
bad habits out of your head as soon as possible, otherwise you'll keep doing them later on.
 
for someone intrested in learning programing where do you start? it all seems confusing anyone know some good in depth tutorials?
 
for someone intrested in learning programing where do you start? it all seems confusing anyone know some good in depth tutorials?

Thread bumping??

Does your school offer programming classes? (HTML does not count)

Really, once you learn the bascis of programming (how when to use an if/while/for, etc), the rest is all about logical thinking....
 
Status
Not open for further replies.
Back
Top