Unexpectect token error with C++ program?
-
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. /* * 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> using namespace 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:{
-
Answer:
Ummm... WOW, your case is completely messed up. Why do you have the function you are calling inside the case? And why do you have a function definition for main in it? And why do you have everything in your case enclosed in curly brackets? case 1: 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 } break; Then outside of your main put this: //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; }
Dank Hunt at Yahoo! Answers Visit the source
Other answers
I see no point in having that line. what happens if you remove it?
Related Q & A:
- How Can I use .net dll in C program?Best solution by Stack Overflow
- How to run an executable from within a c program?Best solution by Stack Overflow
- What is Msn messenger program error?Best solution by Yahoo! Answers
- Help with c++ grading program.Best solution by Yahoo! Answers
- Can anyone help me with this C++ program?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.