Aug 11, 2014 at 11:16am UTC
HELP about void!!! it outputs error.
49 11 C:\Users\Skye\Documents\wh.cpp [Error] '::main' must return 'int'
#include <iostream>
#include <fstream>
#include <conio.h>
#include <string>
#include <windows.h>
using namespace std;
const int quit = 7;
const int MAX = 3;
struct tm *Sys_T = NULL;
//set up record structure
struct coffeerec
{
string bean;
int num_in_stock;
string date_purchased;
};
typedef coffeerec coffeeArrayType[3];
coffeeArrayType coffee;
string uname, password;
char ch;
int che;
int in_sys;
int choice;
int amount;
string datebought;
void logon();
void readfile();
void writefile();
void managermenu();
void barristamenu();
void date();
void display();
void processorder();
void addstock();
void manager_act_on_choice();
void barrista_act_on_choice();
// details of the actual array of records
void main() //Line 49
{
date();
logon();
if (in_sys == 1)
{
while (choice !=4)
{
managermenu();
manager_act_on_choice();
}
}
else if (in_sys ==2)
{
while (choice !=3)
{
barristamenu();
barrista_act_on_choice();
}
}
}
void logon()
{
cout << "Enter username: " << "\n";
cin >> uname;
cout << "Enter Password: " << "\n";
ch = _getch();
while (ch!= 13) // 13 is the enter key
{
password.push_back(ch);
cout << "*";
ch=_getch();
}
if (uname.compare ("manager")==0 && password.compare ("man")==0)
{
cout << " Hello Boss \n";
in_sys = 1;
}
else if (uname.compare ("barrista")==0 && password.compare ("bar")==0)
{
cout << "Welcome!!!! What would you like to do today ? \n";
in_sys = 2;
}
else
cout << "Bah Humbug - Go away";
}
void writefile()
{
}//end method
void addstock()
{
string beans;
ofstream fileout("m:\\coffeeAdd.txt",ios::app);
cout << "Enter bean to append: \n";
cin >> beans;
cout << "Please enter date bought: \n";
cin >> datebought;
cout << "Please enter amount: \n";
cin >> amount;
fileout << beans << "\t" << datebought << "\t" << amount << "\n";
fileout.close();
}//end method
void readfile()
{ // open the file from reading into array of records. Check that the file exists. Print the contents of the
//array onto screen.
int count = 0;
ifstream filein("m:\\coffee.txt",ios::in);
if (!filein)
{
cout << "cannot read file";
_getch();
exit(1);
}
else
{
for (count = 0;!filein.eof();count++)
{
filein >> coffee[count].bean >> coffee[count].num_in_stock >> coffee[count].date_purchased;
}
filein.close();
}
//display the file
for (count=0;count<3;count++)
cout << coffee[count].bean << "\t" << coffee[count].num_in_stock << "\t " << coffee[count].date_purchased << "\n";
}//end of read file method
void date()
{
SYSTEMTIME time;
GetLocalTime( &time );
cout << time.wMonth << "/" << time.wDay << "/" << time.wYear << endl;
cout << time.wHour << ":" << time.wMinute << endl;
}
void managermenu()
{ // screen output given place code araound
system("cls");
cout << "\t\t MANAGER MENU \n";
cout << "____________________________________________________\n";
cout << "1. View current stock file\n";
cout << "2. Add more stock\n";
cout << "3. Barrista menu\n";
cout << "7 to Exit\n";
cout << "Enter choice: ";
cin >> choice;
}
void manager_act_on_choice()
{
switch(choice)
{
case 1:
{
readfile();
cout<<"Press any key to continue....";
ch = getch();
break;
}
case 2:
{
addstock();
cout<<"Press any key to continue....";
ch = getch();
break;
}
case 3:
{
cout << "This choice will allow you to modify stock";
cout<<"Press any key to continue....";
ch = getch();
break;
}
case 4:
{
cout << "do you want to exit? (Y/N): ";
do
che = getche();
while (che != 'y' && che != 'Y');
exit(0);
}
default: cout << "Error - incorrect choice:";
}//end switch
}//end of method
void barristamenu()
{ // screen output given place code araound
system("cls");
cout << "\t\t BARRISTA MENU \n";
cout << "____________________________________________________\n";
cout << "1. Make order\n";
cout << "2. Update stock file\n";
cout << "7 to Exit (or return to manager menu)\n";
cout << "Enter choice: ";
cin >> choice;
}
void barrista_act_on_choice()
{
switch(choice)
{
case 1:
{
cout << "This choice will allow you to take an order";
cout <<"Press any key to continue....";
ch = getch();
break;
}
case 2:
{
cout << "This choice will allow you to add stock";
cout<<"Press any key to continue....";
ch = getch();
break;
}
case 3:
{
cout << "do you want to exit? (Y/N): ";
do
che = getche();
while (che != 'y' && che != 'Y');
exit(0);
}
default: cout << "Error - incorrect choice:";
}//end switch
}//end of method
void display()
{ // code here
}
void processorder( )
{
int bean_choice;
int bean_pos;
int coffee_choice;
int portions;
string coffee;
int num_cups;
int total_portions;
system("cls");
cout << "select normal or decaffe" << endl;
cout << "1. Normal" << endl;
cout << "2. Decaffe" << endl;
cout << "Select: ";
// screen output given place code araound
cout << "\n\n";
cout << "Now select cofee type" << endl;
cout << "1. Americano" << endl;
cout << "2. Macchiato" << endl;
cout << "3. Espresso" << endl;
cout << "4. Double Espresso" << endl;
cout << "5. Cappuccino" << endl;
cout << "6. Mocha" << endl;
cin >> bean_choice;
cout << "Make selection: ";
cin >> coffee_choice;
// screen output given place code araound
}
Aug 11, 2014 at 1:54pm UTC
Self explanatory. Main must return int so change it to int main()
.
Aug 11, 2014 at 2:41pm UTC
firstly include the code in code tags to improve readability and secondly the void main
must be changed to int main
and include an return 0
at the end of the main
Aug 11, 2014 at 6:01pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
#include <iostream>
#include <fstream>
#include <conio.h>
#include <string>
#include <windows.h>
using namespace std;
const int quit = 7;
const int MAX = 3;
struct tm *Sys_T = NULL;
//set up record structure
struct coffeerec
{
string bean;
int num_in_stock;
string date_purchased;
};
typedef coffeerec coffeeArrayType[3];
coffeeArrayType coffee;
string uname, password;
char ch;
int che;
int in_sys;
int choice;
int amount;
string datebought;
void logon();
void readfile();
void writefile();
void managermenu();
void barristamenu();
void date();
void display();
void processorder();
void addstock();
void manager_act_on_choice();
void barrista_act_on_choice();
// details of the actual array of records
void main() //Line 49
{
date();
logon();
if (in_sys == 1)
{
while (choice !=4)
{
managermenu();
manager_act_on_choice();
}
}
else if (in_sys ==2)
{
while (choice !=3)
{
barristamenu();
barrista_act_on_choice();
}
}
}
void logon()
{
cout << "Enter username: " << "\n" ;
cin >> uname;
cout << "Enter Password: " << "\n" ;
ch = _getch();
while (ch!= 13) // 13 is the enter key
{
password.push_back(ch);
cout << "*" ;
ch=_getch();
}
if (uname.compare ("manager" )==0 && password.compare ("man" )==0)
{
cout << " Hello Boss \n" ;
in_sys = 1;
}
else if (uname.compare ("barrista" )==0 && password.compare ("bar" )==0)
{
cout << "Welcome!!!! What would you like to do today ? \n" ;
in_sys = 2;
}
else
cout << "Bah Humbug - Go away" ;
}
void writefile()
{
}//end method
void addstock()
{
string beans;
ofstream fileout("m:\\coffeeAdd.txt" ,ios::app);
cout << "Enter bean to append: \n" ;
cin >> beans;
cout << "Please enter date bought: \n" ;
cin >> datebought;
cout << "Please enter amount: \n" ;
cin >> amount;
fileout << beans << "\t" << datebought << "\t" << amount << "\n" ;
fileout.close();
}//end method
void readfile()
{ // open the file from reading into array of records. Check that the file exists. Print the contents of the
//array onto screen.
int count = 0;
ifstream filein("m:\\coffee.txt" ,ios::in);
if (!filein)
{
cout << "cannot read file" ;
_getch();
exit(1);
}
else
{
for (count = 0;!filein.eof();count++)
{
filein >> coffee[count].bean >> coffee[count].num_in_stock >> coffee[count].date_purchased;
}
filein.close();
}
//display the file
for (count=0;count<3;count++)
cout << coffee[count].bean << "\t" << coffee[count].num_in_stock << "\t " << coffee[count].date_purchased << "\n" ;
}//end of read file method
void date()
{
SYSTEMTIME time;
GetLocalTime( &time );
cout << time.wMonth << "/" << time.wDay << "/" << time.wYear << endl;
cout << time.wHour << ":" << time.wMinute << endl;
}
void managermenu()
{ // screen output given place code araound
system("cls" );
cout << "\t\t MANAGER MENU \n" ;
cout << "____________________________________________________\n" ;
cout << "1. View current stock file\n" ;
cout << "2. Add more stock\n" ;
cout << "3. Barrista menu\n" ;
cout << "7 to Exit\n" ;
cout << "Enter choice: " ;
cin >> choice;
}
void manager_act_on_choice()
{
switch (choice)
{
case 1:
{
readfile();
cout<<"Press any key to continue...." ;
ch = getch();
break ;
}
case 2:
{
addstock();
cout<<"Press any key to continue...." ;
ch = getch();
break ;
}
case 3:
{
cout << "This choice will allow you to modify stock" ;
cout<<"Press any key to continue...." ;
ch = getch();
break ;
}
case 4:
{
cout << "do you want to exit? (Y/N): " ;
do
che = getche();
while (che != 'y' && che != 'Y' );
exit(0);
}
default : cout << "Error - incorrect choice:" ;
}//end switch
}//end of method
void barristamenu()
{ // screen output given place code araound
system("cls" );
cout << "\t\t BARRISTA MENU \n" ;
cout << "____________________________________________________\n" ;
cout << "1. Make order\n" ;
cout << "2. Update stock file\n" ;
cout << "7 to Exit (or return to manager menu)\n" ;
cout << "Enter choice: " ;
cin >> choice;
}
void barrista_act_on_choice()
{
switch (choice)
{
case 1:
{
cout << "This choice will allow you to take an order" ;
cout <<"Press any key to continue...." ;
ch = getch();
break ;
}
case 2:
{
cout << "This choice will allow you to add stock" ;
cout<<"Press any key to continue...." ;
ch = getch();
break ;
}
case 3:
{
cout << "do you want to exit? (Y/N): " ;
do
che = getche();
while (che != 'y' && che != 'Y' );
exit(0);
}
default : cout << "Error - incorrect choice:" ;
}//end switch
}//end of method
void display()
{ // code here
}
void processorder( )
{
int bean_choice;
int bean_pos;
int coffee_choice;
int portions;
string coffee;
int num_cups;
int total_portions;
system("cls" );
cout << "select normal or decaffe" << endl;
cout << "1. Normal" << endl;
cout << "2. Decaffe" << endl;
cout << "Select: " ;
// screen output given place code araound
cout << "\n\n" ;
cout << "Now select cofee type" << endl;
cout << "1. Americano" << endl;
cout << "2. Macchiato" << endl;
cout << "3. Espresso" << endl;
cout << "4. Double Espresso" << endl;
cout << "5. Cappuccino" << endl;
cout << "6. Mocha" << endl;
cin >> bean_choice;
cout << "Make selection: " ;
cin >> coffee_choice;
// screen output given place code araound
}
Use code tags, its easier to read.
Secondly, main() should ALWAYS return an int. Anyone who says otherwise should be slapped across the face (along with virus writers :D).
EDIT:
struct tm *Sys_T = nullptr ;
use nullptr instead of NULL when working with pointers.
Last edited on Aug 11, 2014 at 6:29pm UTC