-
Epected Primary Errors
I am in a beginning programming class, and am having all these syntax errors that i can't fiugre out. Please help!
Code:
/#include <cstdio> //Header Files
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
int main();
int init_function();
enum choice {regular=1, super, superdooper,quit};
choice display_function();
int big_switch();
int calculate(int ,int);
int calculate(int);
int superdooper_loop(int);
int superdooper_calculate(int, char);
void quit_pattern();
void grand_total(int);
static int rand_number;
/************************************************************************************************
MAIN
purpose:
input:
returns:
************************************************************************************************/
int main (){
bool notValid;
enum choice{regular=1, super=2, superdooper=3,quit=4};
int age;
display_function();
do{ //Validation for age
notValid=false;
printf ("\nHow old are you?");
cin >> age;
if (age<1 || age>115)
{
cout << "Invalid entry.\n";
notValid=true;
}
} while (notValid);
int big_switch();
}
/************************************************************************************************
INIT
purpose:
input:
returns:
************************************************************************************************/
int init_function(){
int rand_number = rand();
return(rand_number);
}
/************************************************************************************************
DISPLAY
purpose: displays menu
input: choice
returns: choice
************************************************************************************************/
choice display_function (){
enum choice {regular=1, super=2, superdooper=3,quit=4};
cout << "Welcome to the Fair Price Car Wash\n\n";
cout << "1) Regular Car Wash\n";
cout << "2) Super Car Wash\n";
cout << "3) SuperDooper Car Wash\n";
cout << "4) Quit\n\n\n";
cout << "Select one of the options:";
cin >> choice;
return(choice);
}
/************************************************************************************************
BIG SWITCH
purpose:
input: choice
returns:
************************************************************************************************/
int big_switch(choice){
int passengers, age;
bool notValid;
switch (choice){
case (regular):
int calculate(int age, int number_pass);
break;
case (super):
int calculate(int age);
break;
case (superdooper):
do{
notValid=false; //Valioating for >4 passengers
cout << "\nHow many passengers do you have?";
cin >> passengers;
if (passengers >=4)
{
cout << "Invalid entry.";
notValid=true;
}
}while (notValid);
int superdooper_loop();
break;
case (quit):
int quit_pattern();
void grand_total();
break;
else
cout << "Please enter a valid selection.";
}
/************************************************************************************************
REG CALCULATE
purpose: calculates price for regular
input: number of passengers
returns:
************************************************************************************************/
int calculate(age, passengers){
if (passengers>3)
{
fee=passengers*age;
grandtotal=grandtotal+fee; //Calculating price for #1
printf ("%30s","The price for you is $");
printf ("%-5.2lf", fee);
cout << "\n\n";
printf ("%30s","The grand total is $");
printf ("%-5.2lf\n", grandtotal);
}
else
{
for(a=0;a<passengers;a++) //Display as many starts as the number of passengers
cout << "*\n";
grandtotal=grandtotal+fee;
printf ("%30s","The price for you is $");
printf ("%-5.2lf", fee);
cout << "\n\n";
printf ("%30s","The grand total is $");
printf ("%-5.2lf""\n", grandtotal);
}
void grand_total();
cout << "The fee is: ", fee;
}
/************************************************************************************************
SUPER CALCULATE
purpose: calculate sproce for super
input:
returns:
************************************************************************************************/
int calculate(int){
double fee;
int age;
double grandtotal=grandtotal+fee; //Calculating price for #2
if (age>=65)
{
fee=(age-65)*.5;
printf ("%30s","The price for you is $");
printf ("%-5.2lf", fee);
cout << "\n\n";
}
else if(age% 2 == 0)
cout << "\nNo Charge\n";
else
{
fee=age;
grandtotal=grandtotal+fee;
printf ("%30s","The price for you is $");
printf ("%-5.2lf", fee);
printf ("%30s","The grand total is $");
printf ("%-5.2lf\n", grandtotal);
cout << "\n\n";
}
void grand_total();
cout << "The fee is: ", fee;
}
/************************************************************************************************
SUPER DOOPER LOOP
purpose: gets age, gender of passengers
input: number of passengers
returns:
************************************************************************************************/
int superdooper_loop(){
int a, passage, passengers;
char passgend;
for (a=1;a<passengers;a++) //Loop for passengers' ages and genders
{
cout << "\nEnter gender of passenger number ";
cout << a, ":";
cin >> passgend;
cout << "\nEnter age of passenger number ";
cout << a, ":";
cin >> passage;
}
int superdooper_calculate(a, passage);
}
/************************************************************************************************
SUPER DOOPER CALCULATE
purpose: calculates fee for option 3
input: ages, genders
returns:
************************************************************************************************/
int superdooper_calculate(int passage, int age, char passgend){
int passage, age;
char f;
double fee, grandtotal;
char passgend;
if (passgend=='f') //Calculating for f passenger
{
fee=passage*1.5;
grandtotal=grandtotal+fee;
printf ("%30s","The price for you is $");
printf ("%-5.2lf", fee);
printf ("%30s","The grand total is $");
printf ("%-5.2lf\n", grandtotal);
cout << "\n\n";
}
else //Calculating for f passenger
{
fee=2*age;
grandtotal=grandtotal+fee;
printf ("%30s","The price for you is $");
printf ("%-5.2lf", fee);
printf ("%30s","The grand total is $");
printf ("%-5.2lf\n", grandtotal);
cout << "\n\n";
}
void grand_total();
cout << "The fee is: ", fee;
}
/************************************************************************************************
QUIT PATTERN
purpose: displays star pattern
input: none
returns: none
************************************************************************************************/
int quit_pattern(){
int row, space, asterisk;
for(row=1; row<5; row++)
{
for(space=0; space>4+row; space++)
printf (" ");
for(asterisk=1; asterisk<=2*row; asterisk++) //Displaying stars
printf("*");
cout << endl;
}
}
/************************************************************************************************
GRAND TOTAL
purpose: displays grand total
input: random number
returns:
************************************************************************************************/
void grand_total(){
static int rand_number;
int fee;
rand_number=init_function();
double grandtotal=fee+rand_number;
cout << "The grand total is :", grandtotal;
}
}
Errors:
Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp" -o "C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp: In function `choice display_function()':
C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:77: error: expected primary-expression before ';' token
C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:78: error: expected primary-expression before ')' token
C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp: In function `int big_switch(choice)':
C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:89: error: expected primary-expression before ')' token
C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:113: error: expected primary-expression before "else"
C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:113: error: expected `;' before "else"
C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:122: error: initializer expression list treated as compound expression
C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:122: error: expected `,' or `;' before '{' token
C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:153: error: expected primary-expression before "int"
C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:153: error: expected `;' before "int"
C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:186: error: expected primary-expression before "int"
C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:186: error: expected `;' before "int"
C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:206: error: a function-definition is not allowed here before '{' token
C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:206: error: expected `,' or `;' before '{' token
C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:241: error: expected primary-expression before "int"
C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:241: error: expected `;' before "int"
C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:258: error: expected primary-expression before "void"
C:\Documents and Settings\Compaq_Owner\Desktop\assignment 4 prototype.cpp:258: error: expected `;' before "void"
Execution terminated
-
This area is a little tweaked:
Code:
int big_switch(choice)
{
int passengers, age;
bool notValid;
switch ( choice )
{
case (regular):
int calculate(int age, int number_pass);
break;
case (super):
int calculate(int age);
break;
case (superdooper):
do
{
notValid=false; //Valioating for >4 passengers
cout << "\nHow many passengers do you have?";
cin >> passengers;
if ( passengers >=4 )
{
cout << "Invalid entry.";
notValid=true;
}
}while ( notValid );
int superdooper_loop();
break;
case (quit):
int quit_pattern();
void grand_total();
break;
else
cout << "Please enter a valid selection.";
}
[edit]And this is not the way to call a function:
Code:
int superdooper_calculate(a, passage);
[edit=2]I'm less motiviated to continue when questions are forum-spammed.
http://www.daniweb.com/forums/thread91145.html
http://forums.devshed.com/c-programm...rs-478130.html
-
Code:
#include <stdio.h>
int func (char v);
int main()
{
char c='o';
func(c); /*calls func() with parameter c, which is set to 'o', so it passes the character 'o' to func in func()'s 'char v'. */
return 0;
}
int func(char v)
{
printf ("v is: %c", v);
return 0;
}
-
Code:
cin >> choice;
return(choice);
}
choice is a type ( an enum ).
You can't extract a type from a stream. redefining the enum doesn't help.
try
Code:
choice display_function (){
//enum choice {regular=1, super=2, superdooper=3,quit=4};
int sel;
cout << "Welcome to the Fair Price Car Wash\n\n";
cout << "1) Regular Car Wash\n";
cout << "2) Super Car Wash\n";
cout << "3) SuperDooper Car Wash\n";
cout << "4) Quit\n\n\n";
cout << "Select one of the options:";
cin >> sel;
return static_cast<choice>(sel);
}
Kurt
-
Sorry, I didn't realize it was a bad thing to post in more than one forum. Just hoping to get an answer.
-
Thanks, Kurt. That was a stupid mistake on my part!
-
> Sorry, I didn't realize it was a bad thing to post in more than one forum
Well it isn't, if you post on a forum and you get no response in a couple of days, then you're free to move on and try somewhere else.
But concurrent posts on many forums is basically the same as writing "URGENT" in your attempt to hit as many people as possible.
http://catb.org/~esr/faqs/smart-questions.html#urgent
The downside is it really annoys helpers who frequent multiple forums.
Also, consider http://catb.org/~esr/faqs/smart-questions.html#forum
-
I'll keep that in mind. Thanks for the replies.