I'm new to C++ and i wrote today the following program:
#include <iostream>
using namespace std;
typedef struct item
{
int hour;
int minute;
int second;
void print()
{
cout << hour << ":" << minute << ":" << second << endl;
}
}time;
time nirmul_time(time a);
time* timing_array(int size);
void print_times(time* array, int size);
int main()
{
time* our_array;
int size;
cout << "Give me the size of the array: " << endl;
cin >> size;
our_array = timing_array(size);
print_times(our_array, size);
delete[]our_array;
}
time nirmul_time(time a)
{
a.minute = a.minute + (a.second / 60);
a.second = a.second % 60;
a.hour = a.hour + (a.minute / 60);
a.minute = a.minute % 60;
a.hour = a.hour % 24;
return a;
}
time* timing_array(int size)
{
int i = 0;
bool overflow = false;
time* array;
array = new time[size];
for (i; i < size; i++)
{
cout << "enter the hours: " << endl;
cin >> array[i].hour;
if (array[i].hour > 23)
overflow = true;
cout << "enter the minutes: " << endl;
cin >> array[i].minute;
if (array[i].minute > 59)
overflow = true;
cout << "enter the seconds: " << endl;
cin >> array[i].second;
if (array[i].second > 59)
overflow = true;
if (overflow)
{
nirmul_time(array[i]);
}
overflow = false;
}
return array;
}
void print_times(time* array, int size)
{
int i = 0;
for (i; i < size; i++)
{
array[i].print();
}
}
when i try to run it throught ctrl+F9 or ctrl+F5 the program is not running, and i get the following error:
1>------ Build started: Project: Project1, Configuration: Debug Win32 ------
1>Source.cpp
1>Project1\Project1\Source.cpp(1,1): warning C4335: Mac file format detected: please convert the source file to either DOS or UNIX format
1>Project1\Project1\Source.cpp(1,10): warning C4067: unexpected tokens following preprocessor directive - expected a newline
1>Project1\Project1\Source.cpp(2,1): error C2447: '{': missing function header (old-style formal list?)
1>Project1\Project1\Source.cpp(6,504): error C2065: 'time': undeclared identifier
1>Project1\Project1\Source.cpp(6,510): error C2065: 'array': undeclared identifier
1>Project1\Project1\Source.cpp(6,521): error C2062: type 'int' unexpected
1>Project1\Project1\Source.cpp(6,527): error C2143: syntax error: missing ';' before '{'
1>Project1\Project1\Source.cpp(6,527): error C2447: '{': missing function header (old-style formal list?)
1>Done building project "Project1.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
also when i try to run in through debugger ctrl+F5 i get an error message: enter image description here
i tried to reopen the project, and to run it in online shell but still it does not work, can somebody help me detect the problem?