Normally I do fairly well when setting up a start-up menu, but every since I starting incorporating functions into my program as requested I have been having Unexpected Token and Unable to resolve identifier errors. I am currently using NetBeans 7.1.1 to do my c++ projects. In the past when I get unexpected token errors it was usually due to a misplaced or missing curly bracket or semicolon. However this time I am unable to find the problem. In addition I will leave all the cases empty except for the first one, since I it has been causing errors to all of my programs. Therefore can someone please help me fix these errors?
/*
* File: main.cpp
* Author: Kevin Vo
* Purpose: Using menu for challenge selection
* Chapter: Gaddis Chapter 6
* Problem 1 -> Finds an item's retail price w/ markup % & wholesale cost
* Problem 2 -> Finds the area of a rectangle
* Problem 3 -> Determines which 4 division of a company made the most
* Problem 4 -> Determines which region has the fewest accidents reported
* Problem 5 -> Figures out the falling time of the object
* Problem 6 -> Calculates the kinetic energy of an object
* Problem 7 -> Displays a table with Fahrenheit & Celsius temperature(0F-20F)
* Problem 8 -> Heads or Tails generator
* Problem 9 -> Calculates the present value to deposit in savings account
* Problem 10 -> Determines the test scores' average
* Created on May 10, 2012, 7:18 AM
*/
#include <cstdlib>
#include <iostream>
#include <iomanip>
usingnamespace std;
int main(int argc, char** argv) {
int choice;
bool loop = true;
do{
cout<<"\n***********************\n";
cout<<"Type 1 to solve problem 1\n";
cout<<"Type 2 to solve problem 2\n";
cout<<"Type 3 to solve problem 3\n";
cout<<"Type 4 to solve problem 4\n";
cout<<"Type 5 to solve problem 5\n";
cout<<"Type 6 to solve problem 6\n";
cout<<"Type 7 to solve problem 7\n";
cout<<"Type 8 to solve problem 8\n";
cout<<"Type 9 to solve problem 9\n";
cout<<"Type 10 to solve problem 10\n";
cout<<"Type anything else to quit with no solutions.\n";
cin>>choice;
switch(choice){
case 1:{
float calculateRetail(float, float);//Function prototype
int main(int argc, char** argv){//<-- unexpected token error
float wholesaleCOST;
int Markup;
//Output prompt and user input for program
cout<<"Please enter the wholesale cost and markup percentage of an item to "
<<"determine its retail price.\nWholesale Cost: ";
cin>>wholesaleCOST;
cout<<"Markup Percentage: ";
cin>>Markup;
//If statement for input validation (no negative digits)
if (wholesaleCOST < 0 || Markup < 0){
cout<<"Input Validation: Do not accept negative value for either the "
<<"wholesale cost of the\nitem or the markup percentage.\n";
}
else{
calculateRetail(wholesaleCOST, Markup);//function call
}
return 0;
}
//Function
float calculateRetail(float NUMwhole, float NUMmark){//<-- unexpected token error & unable to resolve identifier NUMwhole & NUMmark
float totalRetailPrice;
totalRetailPrice = ((NUMwhole * (NUMmark / 100)) + NUMwhole);//<-- unexpected token error & unable to resolve identifier NUMwhole & NUMmark
//output display of the result
cout<<"If an item's wholesale cost is "<<fixed<<setprecision(2)<<showpoint
<<NUMwhole<<" and its mark up percentage is "<<NUMmark//<-- unexpected token error & unable to resolve identifier NUMwhole & NUMmark
<<"%, then the\nitem's retail price is "<<totalRetailPrice<<".\n";
return totalRetailPrice;}
};break;
case 2:{
};break;
case 3:{
};break;
case 4:{
};break;
case 5:{
};break;
case 6:{
};break;
case 7:{
};break;
case 8:{
};break;
case 9:{
};break;
case 10:{
};break;
default:{
cout<<"Exit?"<<endl;
loop=false;
break;
}
}
}while(loop);
return 0;
}
int main(int argc, char** argv) {
int choice;
bool loop = true;
do{
cout<<"\n***********************\n";
cout<<"Type 1 to solve problem 1\n";
cout<<"Type 2 to solve problem 2\n";
cout<<"Type 3 to solve problem 3\n";
cout<<"Type 4 to solve problem 4\n";
cout<<"Type 5 to solve problem 5\n";
cout<<"Type 6 to solve problem 6\n";
cout<<"Type 7 to solve problem 7\n";
cout<<"Type 8 to solve problem 8\n";
cout<<"Type 9 to solve problem 9\n";
cout<<"Type 10 to solve problem 10\n";
cout<<"Type anything else to quit with no solutions.\n";
cin>>choice;
switch(choice){
case 1:{
float calculateRetail(float, float);//Function prototype
int main(int argc, char** argv){//<-- unexpected token error
This is the report that I would receive after running the program. The program works fine on its own but once inserted in to the switch statement for to be part of the menu, I doesn't run correctly anymore.
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/cygdrive/c/Users/DangerousPirate/Documents/NetBeansProjects/Vo_Kevin_Gaddis_Chapter_6_Problems'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin_1-Windows/vo_kevin_gaddis_chapter_6_problems.exe
make[2]: Entering directory `/cygdrive/c/Users/DangerousPirate/Documents/NetBeansProjects/Vo_Kevin_Gaddis_Chapter_6_Problems'
mkdir -p build/Debug/Cygwin_1-Windows
rm -f build/Debug/Cygwin_1-Windows/main.o.d
g++.exe -c -g -MMD -MP -MF build/Debug/Cygwin_1-Windows/main.o.d -o build/Debug/Cygwin_1-Windows/main.o main.cpp
main.cpp: In function `int main(int, char**)':
main.cpp:50: error: a function-definition is not allowed here before '{' token
main.cpp:50: error: expected `,' or `;' before '{' token
main.cpp:75: error: a function-definition is not allowed here before '{' token
main.cpp:75: error: expected `,' or `;' before '{' token
make[2]: *** [build/Debug/Cygwin_1-Windows/main.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
nbproject/Makefile-Debug.mk:65: recipe for target `build/Debug/Cygwin_1-Windows/main.o' failed
make[2]: Leaving directory `/cygdrive/c/Users/DangerousPirate/Documents/NetBeansProjects/Vo_Kevin_Gaddis_Chapter_6_Problems'
nbproject/Makefile-Debug.mk:58: recipe for target `.build-conf' failed
make[1]: Leaving directory `/cygdrive/c/Users/DangerousPirate/Documents/NetBeansProjects/Vo_Kevin_Gaddis_Chapter_6_Problems'
nbproject/Makefile-impl.mk:39: recipe for target `.build-impl' failed