Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C++
#include <stdio.h>

int main() 
{
    // Create a character array that displays the message "My Friends Ages Program"
    char message[] = "My Friends Ages Program";

    // Create a second array that will store 4 integer values
    int ages[4];

    // Use assignment statements to store the friend's ages
    ages[0] = 25;
    ages[1] = 27;
    ages[2] = 24;
    ages[3] = 26;

    // Use a puts() statement to display the message
    puts(message);

    // Use a for() statement to display each age stored in the array element
    for (int i = 0; i < 4; i++) 
	{
        printf("Age of friend %d: %d\n", i + 1, ages[i]);
    }

    return 0;
}


What I have tried:

not sure where to start with troubleshooting.
Posted
Updated 30-Apr-23 1:22am
v4
Comments
Richard MacCutchan 30-Apr-23 6:57am    
What is the problem? When I run it it produces the correct output.
Divine Mills 30-Apr-23 6:59am    
So I am trying to run the code on Dev-C++ and I am unable to see the error message but the line "for (int i = 0; i < 4; i++)" creates the error and I don't understand the issue.
Richard MacCutchan 30-Apr-23 7:02am    
If you get an error you need to tell us what it says, we cannot guess.
Divine Mills 30-Apr-23 7:04am    
My apologies, I will figure out how to find the error and I will get back to you. I am assuming that if you say you can run it without issue then it must be something on my end. Thank You so much for your time:)
Richard MacCutchan 30-Apr-23 7:06am    
Just tell us what the error message says.

Change the for loop as follows:
C++
// Use a for() statement to display each age stored in the array element
int i;
for (i = 0; i < 4; i++)
 
Share this answer
 
In DEV-C++, go to Tools>Compiler Settings>Check Compiler Additional Commands, then enter -std=c99 or -std=c11, then error should resolved.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900