Hello to you all. This is my first post as a member of this site.
I have a question and by that question you will all see that I'm a student of the C++ method of programming, a very basic student at that.
In the program I've entered my code, and my if message, like this
[
{*
int m;
int d;
if(whatever)
{
cout << "statement\n";
}
if(whatever)
{
cout << "another statment\n";
}
cout <<endl;
return 0;
}*]
the problem comes when I try to build the program and the compiler tells me I've left out a lot semi colons before the if brackets and I can't figure out where to put any more semi colons...and I was wondering if I am supposed to put an else in there somewhere or can I continue to bracket off the if's?
If I haven't blocked the code correctly for this statement, I am sorry, like I said, this is my first post.
#include <iostream>
usingnamespace std;
int main()
{
int m;
int d;
if (m >= d)
{
cout << "statement\n";
}
if (d >= m)
{
cout << "another statment\n";
}
cout << endl;
return 0;
}
That should compile correctly. I of course replaced 'whatever' with something that would compile. Since m and d are not initialized the actual output you get may vary, but by process of elimination you will see at least one of your output statements.
All C++ programs must have a main() function. It is the function that the OS executes when you run the program.
To add code, click the "Insert Code" button and paste your code between the BB tags.
[ c o d e ]
code goes here
[ / c o d e ]
(I added spaces just so that the tags aren't actually used and you can see them...)
Ok,
I've talked to a few folks since I posted this question.
Seems I was not putting ( ) around my if statment.
I did not post all of the code that I had, only the part I had a question about.
What it boils down to now is this.
I'm trying to write a program that will output a specific reply based on the users input and I have been told I need to use the if else set up, but when I try, the program will not build. Here is an example, assuming all the other input is correct, like #include <iostream> and using namespace std;
and int main()
int m;
int d;
now, here's the part that I can not figure out properly,
cout << "enter your birthdate, use numbers for month and day\n";
cin >> m>>d;