Hello ladies and gents,

I just made the next exercise of this book and although it works as it should, [I]I was wondering if any of you guys could tell me whether or not it could be improved.[/I]
The exercise goes as follows:

  • Define a table of the names of months of the year and the number of days in each month. Write out that table. Do this twice: once using an array of char for the names and an array for the number fo days and once using an array of structures, with each structure holding the name of a month and the number of days in it.

I also added the following, initialized the struct with the values of the two arrays days and months and see the sizeof both arrays and the size of the struct and struct array.

Here's the code:

include <iostream>

include <string>

struct Date
std::string strMonth;
int strDays;

int main()
Date dt[12];

std::cout << "Using two arrays:\n";

char month[][12] = { "January", "February", "March", "April", "May", "June", 
    "July", "August", "September", "October", "November", "December"};
int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

for (size_t i = 0; i < 12; i++)
    std::cout << days[i] << ' ' << month[i] << '\n';

std::cout << std::endl;

std::cout << "Using an array of struct:\n";

for (size_t i = 0; i < 12; i++)
    dt[i].strMonth = month[i];
    dt[i].strDays = days[i];

for (size_t i ...

Hi guys,

Just wanted to ask you're opinions about this program I had to write for evening school, the idea is when you enter a phrase wich isn't longer then 80 letters, the programm will count the amount of each letter wich is written :!:

It doesn't have to keep account of 'a' or 'A', and I had to show each letter of the alphabet, just in case you we're wondering.

So, if you could just give me some pointers ;) in wich way I could improve it, I would appreciate very much :)

// AantalLetters.cpp : Johan Berntzen: 11/11/2004

#include <stdafx.h>
#include <iostream.h>
#include <iomanip.h>

int zoek(const char s[], char ch);

void main(void)
    int amount=0;
    char str[80], letter='a';

    cout<< " Write a phrase: ";

    for (int i=0;i<26;i++)
        amount=zoek(str, letter);
        cout<< letter << " = "<< amount;

int zoek(const char s[], char ch)
    short a=0;

    for (int i=0;i<s[i];i++)
        if (s[i]==ch)
    return a;
Dave Sinkula commented: Use code tags. +0