Hmm well ive been experimenting a little and lookd around and cant find why this is being a problem
Says incompatable types in the defined item section
Code:
#include <iostream>
#include <conio.h>
#include <windows.h>
#include "Person.h"
#include "Item.h"
using namespace std;
int main(){
Item cherry, ruby, wheat;
///////////////////////////////Defined items////////////////////////////////////
cherry.amount = 56; ruby.name = "Ruby"; wheat.name = "Wheat";
cherry.price = 2; ruby.price =60; wheat.price = 4;
cherry.name = "Cherry"; ruby.amount = 2; wheat.amount = 104;
///////////////////////////////Input variables//////////////////////////////////
char choice;
///////////////////////////////Special Variables////////////////////////////////
int size;
int x;
///////////////////////////////Dialog///////////////////////////////////////////
char welcometoshop[]="Hello thier young sir would you like to look at my fine wares?\n";
char trade[]="The trader pulls up a chest and as you peer in you see....";
//////////////////////////Programstart//////////////////////////////////////////
size=strlen(welcometoshop); //The shop keeper sayss hello
for(x=0;x<size;x++)
{
Sleep(30);
printf("%c", welcometoshop[x]);
}
printf("<Y>es\n<N>o\n");
for(;;)
{
choice=toupper(getch());
if(choice=='Y')
{
system("cls");
size=strlen(trade);
for(x=0;x<size;x++)
{
Sleep(30);
printf("%c", trade[x]);
}
Sleep(700);
printf(cherry.name, "\tPrice:", cherry.price, "\tAmount:", cherry.amount, "\n");
printf(ruby.name, "\tPrice:", ruby.price, "\tAmount:", ruby.amount, "\n");
printf(wheat.name, "\tPrice:", wheat.price, "\tAmount:", wheat.amount, "\n");
}
else if(choice ='N')
{
break;
}
}
return 0;
}
Code:
//Class//
#ifndef ITEM_H
#define ITEM_H
#include <iostream>
#include <string>
using namespace std;
class Item {
public:
char name[];
int price;
int amount;
};
#endif
And with the little prog u made do u put the set name in the class cause then u really cant define it in the program
And would this be correct
Code:
//Class//
#ifndef ITEM_H
#define ITEM_H
#include <iostream>
#include <string>
using namespace std;
class Item {
private:
char name[];
int price;
int amount;
public:
std::string getName() {
return name;
}
return price;
return amount;
void setName() {
name = "sword";
}
};
#endif
int main()
{
item.setName("sword2");
std::cout << item.getName() << std::end1;