D
Developwebsites
/*
why doesnt char* city; work when entering a string,
but char city[256]; does?
I have to store city names and their temps in an array,
and then output all info. how do i utilize arrays in this
program? */
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
class Cities {
private:
char city[256];
int temp;
public:
void prclass();
Cities();
pause();
};
void Cities:: prclass()
{
cout<<'\n'<<city<<" "<<temp;
}
Cities:: Cities()
{
int t=0;
char answer;
do{
cout<<"\n\n";
cout<<"please enter name of city#"<<t+1<<": ";cin>>city;
cout<<"\nplease enter "<<city<<"'s temp: ";cin>>temp;
t++;
cout<<"\nAnother city?(Y/N)";
cin>>answer;
}while(answer =='y' || answer =='Y');
cout<<"\n\n";
}
void pause() {
cout<<"\n\n";
cout<<"Press >ENTER< to continue...";
cout<<"\n\n";
cin.get();
}//close of pause
int main()
{
clrscr();
Cities var;
var.prclass();
pause();
return 0;
}
why doesnt char* city; work when entering a string,
but char city[256]; does?
I have to store city names and their temps in an array,
and then output all info. how do i utilize arrays in this
program? */
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
class Cities {
private:
char city[256];
int temp;
public:
void prclass();
Cities();
pause();
};
void Cities:: prclass()
{
cout<<'\n'<<city<<" "<<temp;
}
Cities:: Cities()
{
int t=0;
char answer;
do{
cout<<"\n\n";
cout<<"please enter name of city#"<<t+1<<": ";cin>>city;
cout<<"\nplease enter "<<city<<"'s temp: ";cin>>temp;
t++;
cout<<"\nAnother city?(Y/N)";
cin>>answer;
}while(answer =='y' || answer =='Y');
cout<<"\n\n";
}
void pause() {
cout<<"\n\n";
cout<<"Press >ENTER< to continue...";
cout<<"\n\n";
cin.get();
}//close of pause
int main()
{
clrscr();
Cities var;
var.prclass();
pause();
return 0;
}