can anyone help me fix this??? I have to do all of this in functions, but i keep getting somethings wrong. Thanks!


Sample Run (The user’s entry is in bold)

Enter the Students Id:5656
Enter how many courses-up to 3: 6
Invalid number! Try again
Enter how many courses-up to 3: 3
Enter the 3 course number(s): 4587 4599 9696
Sorry, you can’t cumulate more than 7 credit hours
Do you want to try again (Y/N): y
Enter how many courses-up to 3: 2
Enter the 2 course number(s): 4587 4599
Thank you!
Press Any Key to Continue...

VALENCIA COMMUNITY COLLEGE
ORLANDO FL 10101
--------------------
Fee Invoice Prepared for Student V5656
1 Credit Hour = $120.25

CRN CR_PREFIX CR_HOURS
4587 MAT 236 4 $ 481.00
4599 COP 220 3 $ 360.75

Health & id fees $ 35.00

--------------------------------------
Total Payments $ 876.75
Goodbye!


code:


#include <iostream>
#include <iomanip>
using namespace std;

void Courses ();
void Receipt ();
void studentid ();

main ()
{
int crn1 = 0;
int crn2 = 0;
int crn3 = 0;
int studentid;
int num;
int course1 = 0;
int course2 = 0 ;
int course3 = 0 ;
double total1;
double total2;
double total3;
double healthfees = 35.00;
double finalprice;
char answer ;


Courses ();

cout <<"Enter the Students Id: ";
cin >> studentid;
cout <<"\n";

cout <<"Enter how many courses-up to 3: ";
cin >> num;
cout <<"\n";

while (num < 1 || num >= 4)
{
cout<<"Invalid number! Try again\n\n";
cout <<"Enter how many courses-up to 3: ";
cin >> num;
cout <<"\n";
}


switch (num)
{
case 3 : cout <<"Enter the 3 course numbers: ";
cin >> course1 >> course2 >> course3;
cout <<"\n";
break;
case 2 : cout <<"Enter the 2 course numbers: ";
cin >> course1 >> course2;
cout <<"\n";
break;
case 1 : cout <<"Enter 1 course number: ";
cin >> course1;
cout <<"\n";
break;
default : cout <<"Invalid number! Try again!\n\n";


system ("pause");
return 0;
}

switch (course1)
{
case 4587 : crn1 = 4;
break;
case 4599 : crn1 = 3;
break;
case 8997 : crn1 = 1;
break;
case 9696 : crn1 = 3;
}

switch (course2)
{
case 4587 : crn2 = 4;
break;
case 4599 : crn2 = 3;
break;
case 8997 : crn2 = 1;
break;
case 9696 : crn2 = 3;
}

switch (course3)
{
case 4587 : crn3 = 4;
break;
case 4599 : crn3 = 3;
break;
case 8997 : crn3 = 1;
break;
case 9696 : crn3 = 3;
}


if (crn1 + crn2 + crn3 > 7);
{
cout<< "Sorry, you can't cumulate more than 7 credit hours.\n\n";
cout<< "Would you like to try again? (Y/N): ";
cin>> answer;
cout<<"\n";

if (answer == 'y');
cout <<"Enter how many courses-up to 3: ";
cin >> num;
cout <<"\n";
}

switch (num)
{
case 3 : cout <<"Enter the 3 course numbers: ";
cin >> course1 >> course2 >> course3;
cout <<"\n";
break;
case 2 : cout <<"Enter the 2 course numbers: ";
cin >> course1 >> course2;
cout <<"\n";
break;
case 1 : cout <<"Enter 1 course number: ";
cin >> course1;
cout <<"\n";
break;
default : cout <<"Invalid number! Try again!\n\n";
}


if (answer == 'n');
{
cout <<"Thank you!\n\n";

}

Receipt ();

//payment calculations
total1 = crn1*120.25;
total2 = crn2*120.25;
total3 = crn3*120.25;
finalprice = healthfees +total1 +total2 +total3;

//Display for receipt

if ( course1 == 4587 || course1==4599 || course1==8997 || course1==9696 )
{


switch (course1)
{
case 4587 : cout<<" "<<course1<<"\t MAT 236\t\t4\t $ "<<total1<<"\n\n";
break;
case 4599 : cout<<" "<<course1<<"\t COP 220\t\t3\t $ "<<total1<<"\n\n";
break;
case 8997 : cout<<" "<<course1<<"\t GOL 124\t\t1\t $ "<<total1<<"\n\n";
break;
case 9696 : cout<<" "<<course1<<"\t COP 100\t\t3\t $ "<<total1<<"\n\n";
break;
}
}
if ( course2 == 4587 || course2==4599 || course2==8997 || course2==9696 )
{

switch (course2)
{
case 4587 : cout<<" "<<course2<<"\t MAT 236\t\t4\t $ "<<total2<<"\n\n";
break;
case 4599 : cout<<" "<<course2<<"\t COP 220\t\t3\t $ "<<total2<<"\n\n";
break;
case 8997 : cout<<" "<<course2<<"\t GOL 124\t\t1\t $ "<<total2<<"\n\n";
break;
case 9696 : cout<<" "<<course2<<"\t COP 100\t\t3\t $ "<<total2<<"\n\n";
break;
}
}
cout<<"\n";
if (course3 == 4587 || course3==4599 || course3==8997 || course3==9696 )
{

switch (course3)
{
case 4587 : cout<<" "<<course3<<"\t MAT 236\t\t4\t $ "<<total3<<"\n\n";
break;
case 4599 : cout<<" "<<course3<<"\t COP 220\t\t3\t $ "<<total3<<"\n\n";
break;
case 8997 : cout<<" "<<course3<<"\t GOL 124\t\t1\t $ "<<total3<<"\n\n";
break;
case 9696 : cout<<" "<<course3<<"\t COP 100\t\t3\t $ "<<total3<<"\n\n";
break;
}
}

cout<<"\n";
cout<<" Health and I.D. fees: $" <<healthfees <<"\n\n";
cout<<" ---------------------------------------------\n";
cout<<" Total Payments: $"<<finalprice <<"\n\n\n";


system ("pause");
}

//********
void Courses ()
{
cout <<"Here is the list of all courses Valencia Community College offers: \n\n";
cout <<"\tCRN\t\tCourse Prefix\t\tCredit Hours\n\n";
cout <<"\t4587\t\t MAT 236\t\t 4\n\n";
cout <<"\t4599\t\t COP 220\t\t 3\n\n";
cout <<"\t8997\t\t GOL 124\t\t 1\n\n";
cout <<"\t9696\t\t COP 100\t\t 3\n\n\n";
}
//********
void Receipt ()
{
cout <<"Here is the student's fee invoice:\n\n\n\n";

cout<<fixed <<setprecision(2);
cout<<" Valencia Community College\n";
cout<<" --------------------------------------------\n\n";
cout<<" Fee invoice prepared for student V"<<studentid<<"\n\n";
cout<<" 1 credit hour= $120.25\n\n\n";
cout <<" CRN Course Prefix Credit Hours\n\n\n";
}

when the program ask to try again yes or no, no matter what you put it keeps going, instead of stopping when u put no; when u put 2 courses, it displays 3 in the receipt, and i would like to put the receipt as a function, but don't know how to do it.

CORRECT IT

if (answer == 'y');
{cout <<"Enter how many courses-up to 3: ";
cin >> num;
cout <<"\n"}

.

>> You cant declare function and integer name same in a program . Then how did you run the program.

i'm using dev c++ to run the program... if i put else, it displays " expected primary-expression before "else" and expected `;' before "else", but no ; is missing...

After else always there is a statement and using ; tells that statement is complete specially with if dont use ; it means that if statement has no outer coverge to other statement which make it of no use.

Why dont you try this one

if (answer ==  'y')
{
cout <<"Enter how many courses-up to 3: ";
cin >> num;
cout <<"\n";
}
#include <iostream>
#include <iomanip>
#include<stdlib>
using namespace std;

void Courses ();
void Receipt ();
void studentid ();



main ()
{
int crn1 = 0;
int crn2 = 0;
int crn3 = 0;
int studentid;
int num;
int course1 = 0;
int course2 = 0 ;
int course3 = 0 ;
double total1;
double total2;
double total3;
double healthfees = 35.00;
double finalprice;
char answer ;


Courses ();

cout <<"Enter the Students Id: ";
cin >> studentid;
cout <<"\n";

cout <<"Enter how many courses-up to 3: ";
cin >> num;
cout <<"\n";

while (num < 1 || num >= 4)
{
cout<<"Invalid number! Try again\n\n";
cout <<"Enter how many courses-up to 3: ";
cin >> num;
cout <<"\n";
}


switch (num)
{
case 3 : cout <<"Enter the 3 course numbers: ";
cin >> course1 >> course2 >> course3;
cout <<"\n";
break;
case 2 : cout <<"Enter the 2 course numbers: ";
cin >> course1 >> course2;
cout <<"\n";
break;
case 1 : cout <<"Enter 1 course number: ";
cin >> course1;
cout <<"\n";
break;
default : cout <<"Invalid number! Try again!\n\n";


system ("pause");
return 0;
}

switch (course1)
{
case 4587 : crn1 = 4;
break;
case 4599 : crn1 = 3;
break;
case 8997 : crn1 = 1;
break;
case 9696 : crn1 = 3;
}

switch (course2)
{
case 4587 : crn2 = 4;
break;
case 4599 : crn2 = 3;
break;
case 8997 : crn2 = 1;
break;
case 9696 : crn2 = 3;
}

switch (course3)
{
case 4587 : crn3 = 4;
break;
case 4599 : crn3 = 3;
break;
case 8997 : crn3 = 1;
break;
case 9696 : crn3 = 3;
}


if (crn1 + crn2 + crn3 > 7)
{
cout<< "Sorry, you can't cumulate more than 7 credit hours.\n\n";
cout<< "Would you like to try again? (Y/N): ";
cin>> answer;
cout<<"\n";
if (answer == 'y')
{
cout <<"Enter how many courses-up to 3: ";
cin >> num;
cout <<"\n";
switch (num)
{
case 3 : cout <<"Enter the 3 course numbers: ";
cin >> course1 >> course2 >> course3;
cout <<"\n";
break;
case 2 : cout <<"Enter the 2 course numbers: ";
cin >> course1 >> course2;
cout <<"\n";
break;
case 1 : cout <<"Enter 1 course number: ";
cin >> course1;
cout <<"\n";
break;
default : cout <<"Invalid number! Try again!\n\n";
}
else if (answer == 'n');
{
cout <<"Thank you!\n\n";
exit 0;
}
}
Receipt ();



//payment calculations
total1 = crn1*120.25;
total2 = crn2*120.25;
total3 = crn3*120.25;
finalprice = healthfees +total1 +total2 +total3;

//Display for receipt

if ( course1 == 4587 || course1==4599 || course1==8997 || course1==9696 )
{


switch (course1)
{
case 4587 : cout<<" "<<course1<<"\t MAT 236\t\t4\t $ "<<total1<<"\n\n";
break;
case 4599 : cout<<" "<<course1<<"\t COP 220\t\t3\t $ "<<total1<<"\n\n";
break;
case 8997 : cout<<" "<<course1<<"\t GOL 124\t\t1\t $ "<<total1<<"\n\n";
break;
case 9696 : cout<<" "<<course1<<"\t COP 100\t\t3\t $ "<<total1<<"\n\n";
break;
}
}
if ( course2 == 4587 || course2==4599 || course2==8997 || course2==9696 )
{

switch (course2)
{
case 4587 : cout<<" "<<course2<<"\t MAT 236\t\t4\t $ "<<total2<<"\n\n";
break;
case 4599 : cout<<" "<<course2<<"\t COP 220\t\t3\t $ "<<total2<<"\n\n";
break;
case 8997 : cout<<" "<<course2<<"\t GOL 124\t\t1\t $ "<<total2<<"\n\n";
break;
case 9696 : cout<<" "<<course2<<"\t COP 100\t\t3\t $ "<<total2<<"\n\n";
break;
}
}
cout<<"\n";
if (course3 == 4587 || course3==4599 || course3==8997 || course3==9696 )
{

switch (course3)
{
case 4587 : cout<<" "<<course3<<"\t MAT 236\t\t4\t $ "<<total3<<"\n\n";
break;
case 4599 : cout<<" "<<course3<<"\t COP 220\t\t3\t $ "<<total3<<"\n\n";
break;
case 8997 : cout<<" "<<course3<<"\t GOL 124\t\t1\t $ "<<total3<<"\n\n";
break;
case 9696 : cout<<" "<<course3<<"\t COP 100\t\t3\t $ "<<total3<<"\n\n";
break;
}
}

cout<<"\n";
cout<<" Health and I.D. fees: $" <<healthfees <<"\n\n";
cout<<" ---------------------------------------------\n";
cout<<" Total Payments: $"<<finalprice <<"\n\n\n";




system ("pause");
}

//********
void Courses ()
{
cout <<"Here is the list of all courses Valencia Community College offers: \n\n";
cout <<"\tCRN\t\tCourse Prefix\t\tCredit Hours\n\n";
cout <<"\t4587\t\t MAT 236\t\t 4\n\n";
cout <<"\t4599\t\t COP 220\t\t 3\n\n";
cout <<"\t8997\t\t GOL 124\t\t 1\n\n";
cout <<"\t9696\t\t COP 100\t\t 3\n\n\n";
}
//********
void Receipt ()
{
cout <<"Here is the student's fee invoice:\n\n\n\n";

cout<<fixed <<setprecision(2);
cout<<" Valencia Community College\n";
cout<<" --------------------------------------------\n\n";
cout<<" Fee invoice prepared for student V"<<studentid<<"\n\n";
cout<<" 1 credit hour= $120.25\n\n\n";
cout <<" CRN Course Prefix Credit Hours\n\n\n";
}
This article has been dead for over six months. Start a new discussion instead.