well, i have been working on two projects....

in of the projects i am getting two errors which i am unable to rectify ....please please could you possible identify the two errors for me...?? i shall be really really grateful..

you can try running the below program in Microsoft visual c++ 6.0 and you will see two errors like this :-
(C:\Documents and Settings\Owner\Desktop\project.cpp(206) : warning C4390: ';' : empty controlled statement found; is this the intent?
C:\Documents and Settings\Owner\Desktop\project.cpp(208) : error C2664: 'class istream &__thiscall istream::read(char *,int)' : cannot convert parameter 1 from 'char' to 'char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Owner\Desktop\project.cpp(208) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.

project.exe - 2 error(s), 1 warning(s)
)

# include<iostream.h>
# include<fstream.h>
# include<stdio.h>
#include<string.h>



void add();
void update();
void delitem();
void search();
void admin();
void cust();
void update();
void csearch();
void purchase();

class mobile
{char modelno[10];
char brand[20];
char specs[100];
float price;
char warranty[10];
public:
	void getdata()
	{cout<<"enter the brand of the phone"<<endl;
	cin.getline(brand,20);
	cout<<"enter the model of the phone";
    cin.getline(modelno,10);
	cout<<"enter the specifications of the phone joined by ','"<<endl;
    cin.getline(specs,100);
    cout<<"enter the warranty period"<<endl;
	cin.getline(warranty,10);
	cout<<"enter the price of the phone"<<endl;
	cin>>price;
		}
void putdata()
{cout<<"BRAND :"<<brand<<endl<<"MODEL :"<<modelno<<endl<<"SPECIFICATIONS :"<<specs<<endl<<"PRICE :Dh"<<price;
}
void getmodelno()
{cout<<modelno;
}
void getbrand()
{cout<<brand;
}

};
class laptop
{ char brand[20];
  char lmodelno[10];
  int harddisk;
  int ram;
  char os[20];
  char processor[10];
  char warranty[10];
  int price;
public:
	void getlaptop()
	{cout<<"enter the brand "<<endl;
	cin.getline(brand,20);
	cout<<"enter the model number"<<endl;
	cin.getline(lmodelno,10);
	cout<<"enter the size of the hard disk"<<endl;
	cin>>harddisk;
	cout<<"enter the ram"<<endl;
	cin>>ram;
	cout<<"enter the operating system "<<endl;
	cin.getline(os,20);
    cout<<"enter the processor "<<endl;
	cin.getline(processor,10);
	cout<<"enter the warranty period"<<endl;
	cin.getline(warranty,10);
	cout<<"enter the price"<<endl;
	cin>>price;
	}
    void putlaptop()
	{cout<<"COMPANY :"<<brand<<endl<<"MODEL :"<<lmodelno<<endl<<"HARD DISK SPACE :"<<harddisk<<"GB"<<endl<<"RAM SIZE :"<<ram<<"GB"<<endl<<"OPERATING SYSTEM :"<<os<<endl<<"PROCESSOR "<<processor<<endl<<"WARRANTY :"<<warranty<<endl<<"PRICE :Dh"<<price;
	}
	
void getmodelno()
{cout<<lmodelno;
}
char getbrand()
{cout<<brand;
}	
};

struct date
{
	int dd,mm,yy;
};

struct address
{
	long int res;
	long int mob;
	char city[50];
	long int pobox;
};

struct name
{
	char first[50];
	char middle[50];
    char last[50];
};

struct creditcard
{
	long int first;
	long int second;
	long int third;
	long int fourth;
};

void main()
{int ch;
do
{cout<<"\n     menu  ";
cout<<"\n WHAT YOU ARE:-";
cout<<"\n 1.ADMINISTRATOR";
cout<<"\n 2.CUSTOMER";
cout<<"\n 3.EXIT";
cout<<"\n ENTER YOUR OPTION"<<endl;
cin>>ch;
switch(ch)
{case 1:admin();
        break;
case 2:cust();
	   break;
}
}while(ch<3);
}

	void admin()
	{int a;
	do
	{
		cout<<"1.Add";
		cout<<"2.Search";
		cout<<"3.Update";
        cout<<"4.Delete";
        cout<<"5.Exit";
		cout<<"Enter your option";
		cin>>a;
		switch(a)
		{case 1:add();
		        break;
		case 2:search();
			   break;
		case 3:update();
			   break;
		case 4:delitem();
			   break;
		}
	}while(a<5);
	}

	void add()
	{
	char option[10];
	int n;
	mobile m;
	laptop l;
	fstream fmob,flap;
	fmob.open("mobile.dat",ios::out);
	flap.open("laptop.dat",ios::out);
    cout<<"What u want to add (mobile or laptop)";
    cin>>option;
    
	if(strcmpi(option,"mobile")==0)
	{
	cout<<"\n enter the no. of cells u want to add";
	cin>>n;
	for(int i=1;i<=n;i++)
	{cout<<"enter the details of mobile no:-"<<i;
	 m.getdata();
	 fmob.write((char*)&m,sizeof(m));
	}
	}
	else if(strcmpi(option,"laptop")==0)
	{cout<<"\n enter the no. of laptops u want to add";
	cin>>n;
	for(int i=1;i<=n;i++)
	{cout<<"enter the details of laptop no:-"<<i;
	 l.getlaptop();
	 flap.write((char*)&l,sizeof(l));
	}}
	else
    cout<<"invalid entry"<<endl;
	}

	void search()
	{mobile m;
	laptop l;
	int found=0;
	char model[20],option[20];
    fstream fmob,flap;
	fmob.open("mobile.dat",ios::out);
	flap.open("laptop.dat",ios::out);
    cout<<"What u want to search (mobile or laptop)";
    cin>>option;
	{	 
	if(strcmpi(option,"mobile")==0);

	cout<<"enter the model no. u want to search"<<endl;
	 cin.getline(model,10);
	while (fmob.read((char)&m,sizeof(m)));
	{if(strcmpi(m.getmodelno(),model)==0)
	{found=1;
	m.putdata();
	break;
	}}
		if (found==0)
		cout<<"no mobile found";
	  fmob.close();

	}
	
	};
	
else if(strcmpi(option,"laptop")==0);
	
	{cout<<"enter the model no u want to search";
	cin.getline(model,10);
	while(flap.read((char*)&l,sizeof(l)))
	{{if(strcmpi(l.getmodelno(),model)==0)
	{found=1;
	l.putlaptop();
	break;
	}
	}
	if (found==0)
		cout<<"no laptop found";
	  flap.close();
	}
    
	else 
		cout<<"no such item available";
	}
	
	void update()
	{mobile m;
	laptop l;
	int found=0;
	char model[10],option[20];
    fstream fmob,flap;
	fmob.open("mobile.dat",ios::out);
	flap.open("laptop.dat",ios::out);
    cout<<"What u want to update (mobile or laptop)";
    cin>>option;

    if(strcmpi(option,"mobile")==0)
	{cout<<"enter the model no. u want to update"<<endl;
	 cin.getline(model,10);
	while (fmob.read((char)&m,sizeof(m)))
	{
	if(strcmpi(m.getmodelno(),model)==0)
	{found=1;
	cout<<"enter the new details";
	m.getdata();
	fmob.seekp((-1)*sizeof(m),ios::cur);
	fmob.write((char*)&m,sizeof(m));
	break;
	}
	}}
	
   else if(strcmpi(option,"laptop")==0)
	{cout<<"enter the model no you want to update";
	cin.getline(model,10);
	
	while(flap.read((char)&l,sizeof(l)))
	
	{if(strcmpi(l.getmodelno(),model)==0)
	{found=1;
    cout<<"enter the new details";
	l.getlaptop();
	flap.seekp((-1)*sizeof(l),ios::cur);
	flap.write((char*)&l,sizeof(l));
	break;
	}
   }}
	else
		cout<<"no such item";
   }

   void delete();
   {mobile m;
	laptop l;
	int found=0;
	char model[10],option[20];
    fstream fmob,flap,ftemp;
	fmob.open("mobile.dat",ios::out);
	flap.open("laptop.dat",ios::out);
	ftemp.open("temp.dat",ios::out);
    cout<<"What u want to delete (mobile or laptop)";
    cin>>option;

    if(strcmpi(option,"mobile")==0)
	{cout<<"enter the model no. u want to delete"<<endl;
	 cin.getline(model,10);
	while (fmob.read((char*)&m,sizeof(m)))
	{if(m.getmodelno()!=model)
	ftemp.write((char*)&m,sizeof(m));
	}
	fmob.close();
	ftemp.close();
	remove("mobile.dat");
	rename("temp.dat","mobile.dat");
	}
     else if(strcmpi(option,"laptop")==0)
	{cout<<"enter the model no. u want to delete"<<endl;
	 cin.getline(model,10);
	while (flap.read((char*)&l,sizeof(l)))
	{if(l.getmodelno()!=model)
	ftemp.write((char*)&l,sizeof(l));
	}
	flap.close();
	ftemp.close();
	remove("laptop.dat");
	rename("temp.dat","laptop.dat");
	}

   else
	   cout<<"no such item";
   }

   void cust()
   {int ch;
     do
	 {cout<<"1.search our products";
	 cout<<"2.purchase an item";
	 cout<<"enter your choice";
	 cin>>ch;

	 switch(ch)
	 {case 1:csearch();
	         break;
	 case 2:purchase();
		    break;
	 }
	 }while(ch<3);
   }


void csearch()
	{mobile m;
	laptop l;
	int found=0;
	char model[10],option[20];
    fstream fmob,flap;
	fmob.open("mobile.dat",ios::out);
	flap.open("laptop.dat",ios::out);
    cout<<"What u want to search (mobile or laptop)";
    cin>>option;
	 
	if(strcmpi(option,"mobile")==0)
	{cout<<"enter the model no. u want to search"<<endl;
	 cin.getline(model,10);
	while (fmob.read((char)&m,sizeof(m)))
	{if(strcmpi(m.getmodelno(),model)==0)
	{found=1;
	m.putdata();
	break;
	}
		if (found==0)
		cout<<"no mobile found";
	  fmob.close();

	}
	}
	else if(strcmpi(option,"laptop")==0)
	{cout<<"enter the model no u want to search";
	cin.getline(model,10);
 	while(flap.read((char)&l,sizeof(l)))
	{if(strcmpi(l.getmodelno(),model)==0)
	{found=1;
	l.putlaptop();
	break;
	}
	}
	if (found==0)
		cout<<"no laptop found";
	  flap.close();
	}
	else 
		cout<<"no such item available";
	}


	void purchase()
	{mobile m;
	date dl;
	address addr;
	name customer;
	creditcard card;
	laptop l;
	int found=0,mm,yy,cvc,mfound=0;
	char brand[10],option[20];
    fstream fmob,flap;
	fmob.open("mobile.dat",ios::out);
	flap.open("laptop.dat",ios::out);
    cout<<"What u want to search (mobile or laptop)";
    cin>>option;
	 
	if(strcmpi(option,"mobile")==0)
	{cout<<"enter the brand u want to search"<<endl;
	 cin.getline(brand,10);
	while (fmob.read((char*)&m,sizeof(m)))
	{if(strcmpi(m.getbrand(),brand)==0)
	{found=1;
	 mfound=1;
	m.putdata();
	}
		if (found==0)
		cout<<"no such brand";
	  fmob.close();

	}
	}
	else if(strcmpi(option,"laptop")==0)
	{cout<<"enter the brand u want to search";
	cin.getline(brand,10);
	while(flap.read((char*)&l,sizeof(l)))
	{if(strcmpi(l.getbrand(),brand)==0)
	{found=1;
	l.putlaptop();
	}
	}
	}
	if (found==0)
	{cout<<"no such brand";
	  flap.close();
	}
	else 
	{	cout<<"do you want to buy";
	   char yesno[5];
	   cin.getline(yesno,5);
	   if(strcmpi(yesno,"yes")==0)
	  {char model[10];
      if(strcmpi(m.getmodelno(),model)==0)
	  {m.putdata();
	  
	   }
	
	 cout<<"please enter your name";
	cout<<"first:";
	cin>>customer.first;
	cout<<"middle:";
	cin>>customer.middle;
    cout<<"last:";
	cin>>customer.last;
	cout<<"enter your address";
    cout<<"city:";
	cin>>addr.city;
	cout<<"pobox:";
	cin>>addr.pobox;
	cout<<"telephone no.:";
	cout<<"residence:";
	cin>>addr.res;
	cout<<"mobile:";
    cin>>addr.mob;
	cout<<"enter the date you want to recieve it";
    cin>>dl.dd>>dl.mm>>dl.yy;
    cout<<"enter your credit card no.";
	cin>>card.first>>card.second>>card.third>>card.fourth;
    cout<<"	enter the expiry date of your card";
	cin>>mm>>yy;
	cout<<"enter your cvc";
	cin>>cvc;
    cout<<"your transaction has been confirmed & the amt will be deducted from your card";
    cout<<"-----------------------------";
    cout<<"-----------------------------";
	cout<<"-----------------------------";
    cout<<"-----------------------------";
	cout<<"invoice";
	cout<<"item:";
	if(mfound==1)
		m.putdata();
	else
		l.putlaptop();
cout<<" name";
	
	cout<<customer.first;
	cout<<customer.middle;
    cout<<customer.last;
	cout<<" your address";
    cout<<"city:";
	cout<<addr.city;
	cout<<"pobox:";
	cout<<addr.pobox;
	cout<<"telephone no.:";
	cout<<"residence:";
	cout<<addr.res;
	cout<<"mobile:";
    cout<<addr.mob;
	cout<<"date of delivery:";
    cout<<dl.dd<<dl.mm<<dl.yy;
    cout<<" credit card no.";
	cout<<"**** **** **** **** "<<card.fourth;
    cout<<" expiry date of your card";
	cout<<mm<<yy;
    cout<<"thank you";
	   }
}}

ok this is the end of one project......

and here is the other idea about project...which i already discussed before...
this is "typing tutor" but i am stuck with some problems.... the problem is that the user has to enter "0" always to end the thing....if you press enter nothing happens...so please tell me how to do it using "enter" ......and if someone press the "backspace key" then the compiler counts that too.....so how to overcome that problem ....and also if suppose someone write an extra character ..then how to output and count that as error..

#include<iostream>
#include<windows.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>
#include<ctime>
using namespace std;

int main()
{
char text[300]="What goes up must come down";

time_t start,end;
int correct=0,wrong=0;
double dif;
char type;
cout<<"\n Please Enter the given text \n";
Sleep(50);
cout<<text<<endl;
time (&start);
int i=0;
while(type!='0')
{
type=getche();
if(text[i]==type)
correct++;
else
wrong++;
i++;
}
wrong--;
i--;
time (&end);
dif = difftime (end,start);
int speed;
speed= (i*60)/dif;
cout<<"\n You took "<<dif<<" seconds to enter the text";
cout<<"\n Correct = "<<correct;
cout<<"\n wrong = "<<wrong;
cout<<"\n total = "<<i;
cout<<"\n speed = "<<speed<<" characters\\minute";
cout<<"\n accuracy = "<<(correct*100)/i<<" %";
cout<<endl;
return 0;
}

Recommended Answers

All 16 Replies

The error messages give you the line number on which the error occurs. I'm not going to count the lines in the code you posted, so I won't bother helping you any more than that.

Put your code in the (code) option before you post, it's too troublesome for people to read and analyze it like this.

I see a mod has fixed up the code tags for you.

Line 204: see that semicolon at the end of that if statement? Delete the semicolon.

line 208: The typecast is incorrect. It should be char* not char

ok, i did the same ^^ as you told above and now i am getting 6 errors with 0 warnings..

errors are :


C:\Documents and Settings\Owner\Desktop\project.cpp(209) : error C2664: 'strcmpi' : cannot convert parameter 1 from 'void' to 'const char *'
Expressions of type void cannot be converted to other types
C:\Documents and Settings\Owner\Desktop\project.cpp(212) : error C2043: illegal break
C:\Documents and Settings\Owner\Desktop\project.cpp(222) : error C2143: syntax error : missing ';' before 'else'
C:\Documents and Settings\Owner\Desktop\project.cpp(224) : error C2447: missing function header (old-style formal list?)
C:\Documents and Settings\Owner\Desktop\project.cpp(256) : error C2664: 'class istream &__thiscall istream::read(char *,int)' : cannot convert parameter 1 from 'char' to 'char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Owner\Desktop\project.cpp(256) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.

project.exe - 6 error(s), 0 warning(s)

You are not supposed to have semicolons after your if and while statements.

line 209: getmodeno() is a void function so it can not be used as a parameter to strcmpi()

I am getting the impression that you did not write the code you posted, but just pasted it into your program. You need to look at the error message, then look at the line that the error message occurred. Most of the time the compiler will tell you what is wrong.

The next error, line 212, is actually caused by the semicolon on at the end of the if statement on line 208.

no i wrote the program myself.... the first program i did by myself

but initially it had 15 errors and i was unable to understand the errors...even by look at the respective line numbers.
i am learning C++ at school and we are supposed to develop a project.

ok i removed that semicolon at line 212...but still it shows 6 errors :/

and i didn't understand the line 209 error....do u mean that i should remove the two brackets from getmodelno() .....???

getmodelno() is a function ....and the object m is accessing the function ..
hence m.getmodelno()
which i used for comparing the strings... i dont understand why it is wrong..? :/

look at the class at the top of your file. It says on line 40 that the function doesn't return anything because it is a void function. All that function does is call cin to get something from the keyboard.

Yes, remove the curly brace before the if statement, it shouldn't be there

I think that the problem lies with the getmodelno() function itself, and what you are expecting it to do. As it is written right now, it prints the model number to the screen, but does not return it's value. If you want the function to act as an accessor (also called a getter), then you'd have to write it as:

char* getmodelno()
{
    return lmodelno;
}

You might want to use the string class instead of C-strings, however, as they are much easier to work with.

On an unrelated note: while void main() is accepted by some compilers, strictly speaking the correct usage is int main() according to the standard. While the standard allows compilers to accept void main() for those cases where there is no OS to return to, it is considered a non-portable extension.

I was also curious as to why you were using such an outdated compiler. VC++ 6.0 is from 1998, and there are several more modern compilers available for free, including the newest version of Visual C++ Express. Are you required to use the older version for class? I know several schools use older compilers as a matter of standards (Turbo C++ being the most notorious), but it is in my arrogant opinion a poor practice.

yes^^ i am required to use this older version in class...... :/
thats why i use it at home too...........
anyways, thanks for your help :)

omit the simecolon in your if condition.

omit the simicolon in your if condition. and this errors will appear in your code.


C:\Documents and Settings\tfi\Desktop\michelle visual basic\c++\project.cpp(211) : error C2664: 'class istream &__thiscall istream::read(char *,int)' : cannot convert parameter 1 from 'char' to 'char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\tfi\Desktop\michelle visual basic\c++\project.cpp(211) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.

project.obj - 2 error(s), 0 warning(s)

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.