Programming question

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.

Thanks for any suggestions,

ACHRN
I don't think the problem has anything to do with semicolons, but given all possibilities I can't be absolutely certain what the error is.

My best guess is that you have posted your complete code, which isn't a complete ("properly-formed") program.

Your .cpp file should look like this (in its entirety):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace 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...)

Hope this helps.
Last edited on
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;

if((m==3 && d>=20)||(m==4 && d<=21))
{
cout << "your zodiac sign is......"\n";
cout << "your horoscope is....."\n";
}

else if((m==4 && d>=22)||(m==5 && d<=20))
{
cout <<"your zodiac sign is .....\n";
cout <<"your horoscope is...\n";
}

//it would continue thru all the zodiac signs according to the date entered.

I can not figure out what I'm doing wrong.

Thanks to anyone that can offer some clear vison on this.

Last edited on
I have resolved this issue.
thanks to anyone that took a look at it.
Topic archived. No new replies allowed.