Never mind. That question was solved by myself.

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

#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?

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

int sum = 0;
for(int i = 0; i < numbers; ++i)
    sum += array[i];
cout << "sum = " << sum;
commented: thanks for your attempt. +1

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?

you mean the code you originally posted in post #1? Well, for starters, numbersuffix is undefined.

Never mind. That question was solved by myself.

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

#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?

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.

commented: thank you for solving my problem +1

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.