943,974 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 841
  • C++ RSS
Jan 25th, 2008
0

Hehe another problem

Expand Post »
Never mind. That question was solved by myself.

anyhow, when I compile my code, I get an error.


C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <windows.h>
  3. using namespace std;
  4.  
  5. int main(){
  6. for (int number=1; number<=6; number++;){
  7. if (number == 1){
  8. numbersuffix = "st";}
  9. else if (number == 2){
  10. numbersuffix = "nd";}
  11. else if (number == 3){
  12. numbersuffix = "rd";}
  13. else {
  14. numbersuffix = "th";}
  15.  
  16. cout << "The suffixes are " << numbersuffix << endl;}
  17.  
  18.  
  19. system("pause");
  20.  
  21. return 0;}

What is wrong with this code? Why does DevC++ give an error?
Last edited by jonathanasdf; Jan 25th, 2008 at 10:47 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jonathanasdf is offline Offline
19 posts
since Jan 2008
Jan 25th, 2008
0

Re: Hehe another problem

in the code you posted, marray is an array of uninitialized integers, which could have any random values. Consequently the code you posted makes absolutely no sense at all. To add up all the values in the array
C++ Syntax (Toggle Plain Text)
  1. int sum = 0;
  2. for(int i = 0; i < numbers; ++i)
  3. sum += array[i];
  4. cout << "sum = " << sum;
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Jan 26th, 2008
0

Re: Hehe another problem

Thank you for your reply, but I had already solved that just moments before you replied.

That part of the code compiles just fine. However, could you tell me what the compilation problem could be in my first code? it says

expected `)' before ';' token
expected primary-expression before ')' token
expected `;' before ')' token
expected `;' before ')' token

I do not see any problems with the code.. so could you tell me why this is happening?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jonathanasdf is offline Offline
19 posts
since Jan 2008
Jan 26th, 2008
0

Re: Hehe another problem

you mean the code you originally posted in post #1? Well, for starters, numbersuffix is undefined.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Jan 26th, 2008
1

Re: Hehe another problem

Never mind. That question was solved by myself.

anyhow, when I compile my code, I get an error.


C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <windows.h>
  3. using namespace std;
  4.  
  5. int main(){
  6. for (int number=1; number<=6; number++;){
  7. if (number == 1){
  8. numbersuffix = "st";}
  9. else if (number == 2){
  10. numbersuffix = "nd";}
  11. else if (number == 3){
  12. numbersuffix = "rd";}
  13. else {
  14. numbersuffix = "th";}
  15.  
  16. cout << "The suffixes are " << numbersuffix << endl;}
  17.  
  18.  
  19. system("pause");
  20.  
  21. return 0;}

What is wrong with this code? Why does DevC++ give an error?
Check your for line, there's an additional semi-colon.

numbersuffix is not declared, consider including string or cstring headers (one or the other).

Not sure why window.h is included, it's not needed.

I'm sure you're aware of the system("pause"); implications.
Reputation Points: 11
Solved Threads: 3
Junior Poster in Training
superjacent is offline Offline
66 posts
since Nov 2007
Jan 26th, 2008
0

Re: Hehe another problem

Yep.

numbersuffix was defined.. just didn't include it there cause it was an excerpt and forgot to include it.

There's an extra semicolon? the last one? Thanks...

and yes, I know of the system("pause") implications, but since this is a project (presentation) and it works on the computer, it is alright. I am not using it anywhere else.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jonathanasdf is offline Offline
19 posts
since Jan 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: fibonacci
Next Thread in C++ Forum Timeline: help on returning string private variables





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC