I am new at this c++ programming thing and i got stocked in this program right here hope someone can help me out id appreciate that

// Program Dinner prints out a dinner menu              // 1


const SALAD = "Green Salad";                            // 2
const MEAT = "Chicken Marsala";                         // 3
const VEGGIE = "Carrots with lemon butter";             // 4
const STARCH = "Mashed potatoes";                       // 5


int main                                                // 6


{ string mainCourse                                     // 7


cout  << "First course: "  << SALAD  << endl;       // 8
mainCourse = MEAT + "with" + VEGGIE + "and"         // 9
+ STARCH;                                       // 10
cout  << "Main course: "  << mainCourse  << endl;   // 11
cout  << "Dessert: "  << DESSERT;                   // 12
}                                                       // 13



whats wrong with it?? i tried to compile it but it shows 5 errors wich are:


C:\lab2.cpp(3) : error C2440: 'initializing' : cannot convert from 'char [12]' to 'const int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\lab2.cpp(4) : error C2440: 'initializing' : cannot convert from 'char [16]' to 'const int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\lab2.cpp(5) : error C2440: 'initializing' : cannot convert from 'char [26]' to 'const int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\lab2.cpp(6) : error C2440: 'initializing' : cannot convert from 'char [16]' to 'const int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\lab2.cpp(10) : error C2239: unexpected token '{' following declaration of 'main'
Error executing cl.exe.


lab2.obj - 5 error(s), 0 warning(s)

Recommended Answers

All 6 Replies

const SALAD = "Green Salad"; // 2

Forgetting anything? Like maybe a data type?

Perhaps a header or two? Basic syntax such as parentheses for functions or a semicolon to terminate a statement? Actually defining a variable named DESSERT?

Listen to Dave's advice, he netted them all!
Let int main() return something like a zero, rather than an empty plate.
Sounds like my kind of menu. What's for DESSERT?

const SALAD = "Green Salad"; // 2

Forgetting anything? Like maybe a data type?

Perhaps a header or two? Basic syntax such as parentheses for functions or a semicolon to terminate a statement? Actually defining a variable named DESSERT?

what kind of data type??? so what do i need to do??
damn this is hard lol im a newbie thou.. :-|

what kind of data type??? so what do i need to do??
damn this is hard lol im a newbie thou.. :-|

Well if mainCourse is a string, what do you think might make sense?

Dave answered your question, and you may assume you learned what he said on school/course before they give you such an assignment. You missed a lot of semicolons and data types, you might want to go over the basics again, you need to understand those before trying to do something.

Another tip: mainCourse = MEAT + "with" + VEGGIE + "and" // 9+ STARCH; // 10 Replace that with: mainCourse = MEAT + " with " + VEGGIE + " and " + STARCH; // 10 spaces are important!

this is an old thread

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.