New to C++, can't fix errors

Hello. I have an assignment for my college course. The assignment is to compile a program, view its errors, and fix them. However, I cannot seem to fix one of them. The teacher isn't very good and she is hard to understand. The program and errors are listen below:

// 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
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


1>------ Build started: Project: dinner, Configuration: Debug Win32 ------
1> dinner.cpp
1>f:\iup\cosc 110\dinner.cpp(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>f:\iup\cosc 110\dinner.cpp(3): error C2440: 'initializing' : cannot convert from 'const char [12]' to 'const int'
1> There is no context in which this conversion is possible
1>f:\iup\cosc 110\dinner.cpp(4): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>f:\iup\cosc 110\dinner.cpp(4): error C2440: 'initializing' : cannot convert from 'const char [16]' to 'const int'
1> There is no context in which this conversion is possible
1>f:\iup\cosc 110\dinner.cpp(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>f:\iup\cosc 110\dinner.cpp(5): error C2015: too many characters in constant
1>f:\iup\cosc 110\dinner.cpp(6): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>f:\iup\cosc 110\dinner.cpp(8): error C2440: 'initializing' : cannot convert from 'const char [16]' to 'int'
1> There is no context in which this conversion is possible
1>f:\iup\cosc 110\dinner.cpp(8): error C2144: syntax error : 'int' should be preceded by ';'
1>f:\iup\cosc 110\dinner.cpp(9): error C2470: 'main' : looks like a function definition, but there is no parameter list; skipping apparent body
1>f:\iup\cosc 110\dinner.cpp(13): error C2001: newline in constant
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Also, every time I try to fix something, I seem to just get more errors. It is very frustrating.
const SALAD = "Green Salad"; // 2

const what? const isn't a variable type, it's a qualifier. That means you can't just have a 'const', it needs to be a 'const int' or a 'const string' or something.

These look like strings to me, so I would change this to const string SALAD = "Green Salad";.

int main // 6

main (and all functions) need a set of parenthesis to indicate that they're functions (this is what the "no parameter list" means in that 2nd to last error ... the parenthesis are the parameter list). Change this to int main()

1
2
mainCourse = MEAT + "with" + VEGGIE + "and // 9
+ STARCH; // 10 

Looks like you're missing your closing quote on line 9
Last edited on
Yes, I tried to write it as const string SALAD and int main(), but I get many more errors as before.

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

const string SALAD = "Green Salad"; // 2
const MEAT = "Chicken Marsala"; // 3
const VEGGIE = 'Carrots with lemon butter'; // 4
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


1>------ Build started: Project: dinner, Configuration: Debug Win32 ------
1> dinner.cpp
1>f:\iup\cosc 110\dinner.cpp(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>f:\iup\cosc 110\dinner.cpp(3): error C2146: syntax error : missing ';' before identifier 'SALAD'
1>f:\iup\cosc 110\dinner.cpp(3): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>f:\iup\cosc 110\dinner.cpp(3): error C2440: 'initializing' : cannot convert from 'const char [12]' to 'int'
1> There is no context in which this conversion is possible
1>f:\iup\cosc 110\dinner.cpp(4): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>f:\iup\cosc 110\dinner.cpp(4): error C2440: 'initializing' : cannot convert from 'const char [16]' to 'const int'
1> There is no context in which this conversion is possible
1>f:\iup\cosc 110\dinner.cpp(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>f:\iup\cosc 110\dinner.cpp(5): error C2015: too many characters in constant
1>f:\iup\cosc 110\dinner.cpp(6): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>f:\iup\cosc 110\dinner.cpp(8): error C2440: 'initializing' : cannot convert from 'const char [16]' to 'int'
1> There is no context in which this conversion is possible
1>f:\iup\cosc 110\dinner.cpp(8): error C2144: syntax error : 'int' should be preceded by ';'
1>f:\iup\cosc 110\dinner.cpp(10): error C2146: syntax error : missing ';' before identifier 'mainCourse'
1>f:\iup\cosc 110\dinner.cpp(10): error C2065: 'mainCourse' : undeclared identifier
1>f:\iup\cosc 110\dinner.cpp(12): error C2065: 'cout' : undeclared identifier
1>f:\iup\cosc 110\dinner.cpp(12): error C2065: 'endl' : undeclared identifier
1>f:\iup\cosc 110\dinner.cpp(13): error C2065: 'mainCourse' : undeclared identifier
1>f:\iup\cosc 110\dinner.cpp(13): error C2001: newline in constant
1>f:\iup\cosc 110\dinner.cpp(14): error C2110: '+' : cannot add two pointers
1>f:\iup\cosc 110\dinner.cpp(15): error C2065: 'cout' : undeclared identifier
1>f:\iup\cosc 110\dinner.cpp(15): error C2065: 'mainCourse' : undeclared identifier
1>f:\iup\cosc 110\dinner.cpp(15): error C2065: 'endl' : undeclared identifier
1>f:\iup\cosc 110\dinner.cpp(16): error C2065: 'cout' : undeclared identifier
1>f:\iup\cosc 110\dinner.cpp(16): error C2065: 'DESSERT' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Try this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream> // didn't include iostream
#include <string> // didn't include string
using namespace std;
const string SALAD = "Green Salad"; // all missed type-specifier: string
const string MEAT = "Chicken Marsala";
const string VEGGIE = "Carrots with lemon butter"; // contained ' instead of "
const string STARCH = "Mashed potatoes"; // missed a ; at the end and a const qualifier
const string DESSERT = "Bananasplit with chocolate sauce";

int main() // forgot ()
{
   string mainCourse;
   cout << "First course: " << SALAD << endl;
   mainCourse = MEAT + " with " + VEGGIE + " and " + STARCH; // forgot a " at the end of "end", also put the STARCH on the same line for readability
   cout << "Main course: " << mainCourse << endl;
   cout << "Dessert: " << DESSERT; // DESSERT was undefined, fixed it now
} // missed ending bracket 
I don't know how you expected this code to actually work.. but whatever; I fixed it.
I did not expect it to work. As I said, the assignment was to fix all the errors. But okay, thanks for your help.
Topic archived. No new replies allowed.