Hehe another problem

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jan 2008
Posts: 19
Reputation: jonathanasdf is an unknown quantity at this point 
Solved Threads: 0
jonathanasdf jonathanasdf is offline Offline
Newbie Poster

Hehe another problem

 
0
  #1
Jan 25th, 2008
Never mind. That question was solved by myself.

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


  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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,407
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1468
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Hehe another problem

 
0
  #2
Jan 25th, 2008
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
  1. int sum = 0;
  2. for(int i = 0; i < numbers; ++i)
  3. sum += array[i];
  4. cout << "sum = " << sum;
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 19
Reputation: jonathanasdf is an unknown quantity at this point 
Solved Threads: 0
jonathanasdf jonathanasdf is offline Offline
Newbie Poster

Re: Hehe another problem

 
0
  #3
Jan 26th, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,407
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1468
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Hehe another problem

 
0
  #4
Jan 26th, 2008
you mean the code you originally posted in post #1? Well, for starters, numbersuffix is undefined.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 66
Reputation: superjacent is an unknown quantity at this point 
Solved Threads: 3
superjacent's Avatar
superjacent superjacent is offline Offline
Junior Poster in Training

Re: Hehe another problem

 
1
  #5
Jan 26th, 2008
Originally Posted by jonathanasdf View Post
Never mind. That question was solved by myself.

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


  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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 19
Reputation: jonathanasdf is an unknown quantity at this point 
Solved Threads: 0
jonathanasdf jonathanasdf is offline Offline
Newbie Poster

Re: Hehe another problem

 
0
  #6
Jan 26th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC