12 Replies - 997 Views - Last Post: 07 December 2009 - 03:53 AM Rate Topic: -----

#1 KoenM  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 41
  • Joined: 07-December 09

C++ programming help needed

Posted 07 December 2009 - 01:59 AM

Hello programmers,

I am trying to make a program in C++, but I am a noob.
Help would be appreciated.

This is my program:

#include <iostream>
#include<cmath>
using namespace std;

int main ()
{
  int a,b,X,ANTWOORD;
    
  for(a=100;a<=999;a+=1){
    for(b=100;b<=999;b+=1){
      X=a*b;
      if(X/100000<1){
        if(floor(X/10000)==floor(X-10*floor(X/10))&&floor((X-10000*floor(X/1000000))/1000)==floor((X-100*floor(X/100))/10)){
          if(X>ANTWOORD){
            ANTWOORD=X;
            };
          };
        else if(floor(X/100000)==floor(X-10*floor(X/10))&&floor((X-100000*floor(X/100000))/10000)==floor((X-100*floor(X/100))/10)&&floor((X-10000*floor(X/10000))/1000)==floor((X-1000*floor(X/1000))/100)){
          if(X>ANTWOORD){
            ANTWOORD=X;
            };
          };
        };
      };
    };


You don't have to read the stuff between the "if-brackets".
But I do get the well-known
"expected primary-expression before else"-error.
I have been searching on the internet,
but I have not found the solution.
What (is/are) my mistake(s)?

By the way:
I know the program is not finished.
I still have no output.
But I first want to get rid of the else-error.

*** MOD EDIT: Added code tags. Please :code: ***

This post has been edited by JackOfAllTrades: 07 December 2009 - 06:40 AM


Is This A Good Question/Topic? 0
  • +

Replies To: C++ programming help needed

#2 EdwinNameless  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 121
  • View blog
  • Posts: 711
  • Joined: 15-October 09

Re: C++ programming help needed

Posted 07 December 2009 - 02:12 AM

The curly brace right before else has a semicolon after: remove it!

As a matter of curiosity, what does your program do?
Was This Post Helpful? 1
  • +
  • -

#3 KoenM  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 41
  • Joined: 07-December 09

Re: C++ programming help needed

Posted 07 December 2009 - 02:18 AM

View PostEdwinNameless, on 7 Dec, 2009 - 01:12 AM, said:

The curly brace right before else has a semicolon after: remove it!

As a matter of curiosity, what does your program do?


Thanks!
The else-error is gone.
To answer your question:
The program should answer this question:
Find the largest palindrome made from the product of two 3-digit numbers.
It's problem four of the following site:
www.projecteuler.net
Was This Post Helpful? 0
  • +
  • -

#4 EdwinNameless  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 121
  • View blog
  • Posts: 711
  • Joined: 15-October 09

Re: C++ programming help needed

Posted 07 December 2009 - 02:33 AM

View PostKoenM, on 7 Dec, 2009 - 08:18 AM, said:

It's problem four of the following site:
www.projecteuler.net


That's what I thought ;)
I am currently working on Problem 54!

This post has been edited by EdwinNameless: 07 December 2009 - 02:34 AM

Was This Post Helpful? 0
  • +
  • -

#5 KoenM  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 41
  • Joined: 07-December 09

Re: C++ programming help needed

Posted 07 December 2009 - 02:40 AM

View PostEdwinNameless, on 7 Dec, 2009 - 01:33 AM, said:

View PostKoenM, on 7 Dec, 2009 - 08:18 AM, said:

It's problem four of the following site:
www.projecteuler.net


That's what I thought ;)
I am currently working on Problem 54!

OK, well I have completed 11 problems right now (not in order).
Untill now everything with Microsoft Excel.
But I am afraid I have to start with programming now.
I have done: 1, 2, 3, 5, 6, 8, 9, 17, 24, 28, 40.
But now that my else-error is gone I still don't have my answer.
I am able to compile it, but it doesn't give an answer.
The end of my program is:

system("PAUSE");
cout<<"grootste is: "<<ANTWOORD;
return 0;
}

Does this mean I have made another mistake?
By the way: I am dutch.
"grootste is" means: "biggest is"
and
"antwoord" means: "answer"
Was This Post Helpful? 0
  • +
  • -

#6 EdwinNameless  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 121
  • View blog
  • Posts: 711
  • Joined: 15-October 09

Re: C++ programming help needed

Posted 07 December 2009 - 02:48 AM

View PostKoenM, on 7 Dec, 2009 - 08:40 AM, said:

Does this mean I have made another mistake?
By the way: I am dutch.


It's ok, nobody's perfect ;)

You should probably remove all the semicolons after the closing braces, they are not useful here. If it is still not working, post the whole code so that we can see what's going on.
Was This Post Helpful? 0
  • +
  • -

#7 KoenM  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 41
  • Joined: 07-December 09

Re: C++ programming help needed

Posted 07 December 2009 - 02:58 AM

View PostEdwinNameless, on 7 Dec, 2009 - 01:48 AM, said:

View PostKoenM, on 7 Dec, 2009 - 08:40 AM, said:

Does this mean I have made another mistake?
By the way: I am dutch.


It's ok, nobody's perfect ;)

You should probably remove all the semicolons after the closing braces, they are not useful here. If it is still not working, post the whole code so that we can see what's going on.

#include <iostream>
#include<cmath>
using namespace std;

int main ()
{
  int a,b,X,ANTWOORD;
    
  for(a=100;a<=999;a++){
    for(b=a;b<=999;b+=1){
      X=a*b;
      if(X/100000<1){
        if(floor(X/10000)==floor(X-10*floor(X/10))&&floor((X-10000*floor(X/1000000))/1000)==floor((X-100*floor(X/100))/10)){
          if(X>ANTWOORD){
            ANTWOORD=X;
            }
          }
        else if(floor(X/100000)==floor(X-10*floor(X/10))&&floor((X-100000*floor(X/100000))/10000)==floor((X-100*floor(X/100))/10)&&floor((X-10000*floor(X/10000))/1000)==floor((X-1000*floor(X/1000))/100)){
          if(X>ANTWOORD){
            ANTWOORD=X;
            }
          }
        }
      }
    }
  system("PAUSE");
  cout<<"grootste is: "<<ANTWOORD;
  return 0;
  }


*** MOD EDIT: Added code tags. Please :code: ***

This post has been edited by JackOfAllTrades: 07 December 2009 - 06:40 AM

Was This Post Helpful? 0
  • +
  • -

#8 EdwinNameless  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 121
  • View blog
  • Posts: 711
  • Joined: 15-October 09

Re: C++ programming help needed

Posted 07 December 2009 - 03:02 AM

You need to include cstdlib for the system function.
Was This Post Helpful? 0
  • +
  • -

#9 KoenM  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 41
  • Joined: 07-December 09

Re: C++ programming help needed

Posted 07 December 2009 - 03:24 AM

View PostEdwinNameless, on 7 Dec, 2009 - 02:02 AM, said:

You need to include cstdlib for the system function.


Ok, thanks.
Done that, but still no answer.
Was This Post Helpful? 0
  • +
  • -

#10 EdwinNameless  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 121
  • View blog
  • Posts: 711
  • Joined: 15-October 09

Re: C++ programming help needed

Posted 07 December 2009 - 03:27 AM

View PostKoenM, on 7 Dec, 2009 - 09:24 AM, said:

View PostEdwinNameless, on 7 Dec, 2009 - 02:02 AM, said:

You need to include cstdlib for the system function.


Ok, thanks.
Done that, but still no answer.


Right. But you're calling "pause", maybe you just need to put pause *after* you display the result!!
Was This Post Helpful? 1
  • +
  • -

#11 KoenM  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 41
  • Joined: 07-December 09

Re: C++ programming help needed

Posted 07 December 2009 - 03:32 AM

View PostEdwinNameless, on 7 Dec, 2009 - 02:27 AM, said:

View PostKoenM, on 7 Dec, 2009 - 09:24 AM, said:

View PostEdwinNameless, on 7 Dec, 2009 - 02:02 AM, said:

You need to include cstdlib for the system function.


Ok, thanks.
Done that, but still no answer.


Right. But you're calling "pause", maybe you just need to put pause *after* you display the result!!

Aha, that was a stupid mistake.
Now I do get an answer, but it is:
2088763392
I'm quite sure that isn't right.
Because the biggest number possible is 999 x 999 = 998001
We're getting there.
Thanks a lot for your help so far.
Was This Post Helpful? 0
  • +
  • -

#12 EdwinNameless  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 121
  • View blog
  • Posts: 711
  • Joined: 15-October 09

Re: C++ programming help needed

Posted 07 December 2009 - 03:39 AM

View PostKoenM, on 7 Dec, 2009 - 09:32 AM, said:

2088763392
I'm quite sure that isn't right.
Because the biggest number possible is 999 x 999 = 998001


That, and the "little" problem that the number you found is obviously not palindromic...
Was This Post Helpful? 0
  • +
  • -

#13 KoenM  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 41
  • Joined: 07-December 09

Re: C++ programming help needed

Posted 07 December 2009 - 03:53 AM

View PostEdwinNameless, on 7 Dec, 2009 - 02:39 AM, said:

View PostKoenM, on 7 Dec, 2009 - 09:32 AM, said:

2088763392
I'm quite sure that isn't right.
Because the biggest number possible is 999 x 999 = 998001


That, and the "little" problem that the number you found is obviously not palindromic...


Exactly!
And I need to complete 50 of these euler-problems.
Now I am already stuck at 11
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1