| | |
Hehe another problem
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jan 2008
Posts: 19
Reputation:
Solved Threads: 0
Never mind. That question was solved by myself.
anyhow, when I compile my code, I get an error.
What is wrong with this code? Why does DevC++ give an error?
anyhow, when I compile my code, I get an error.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <windows.h> using namespace std; int main(){ for (int number=1; number<=6; number++;){ if (number == 1){ numbersuffix = "st";} else if (number == 2){ numbersuffix = "nd";} else if (number == 3){ numbersuffix = "rd";} else { numbersuffix = "th";} cout << "The suffixes are " << numbersuffix << endl;} system("pause"); 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.
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)
int sum = 0; for(int i = 0; i < numbers; ++i) sum += array[i]; 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.
•
•
Join Date: Jan 2008
Posts: 19
Reputation:
Solved Threads: 0
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?
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?
•
•
•
•
Never mind. That question was solved by myself.
anyhow, when I compile my code, I get an error.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <windows.h> using namespace std; int main(){ for (int number=1; number<=6; number++;){ if (number == 1){ numbersuffix = "st";} else if (number == 2){ numbersuffix = "nd";} else if (number == 3){ numbersuffix = "rd";} else { numbersuffix = "th";} cout << "The suffixes are " << numbersuffix << endl;} system("pause"); return 0;}
What is wrong with this code? Why does DevC++ give an error?
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. •
•
Join Date: Jan 2008
Posts: 19
Reputation:
Solved Threads: 0
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.
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.
![]() |
Similar Threads
- read to end of line problem (C)
- Very strange hard drive failure problem, stumped totally. (Troubleshooting Dead Machines)
- copy constructor problem (C++)
- Display Problem (Monitors, Displays and Video Cards)
- having problem..click me something...please help me out. (Viruses, Spyware and other Nasties)
- n00b problem (Java)
- Layout in CSS (HTML and CSS)
- IE problem with "about:blank" & "search for..." (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: fibonacci
- Next Thread: help on returning string private variables
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






