Hi everyone,

I can't get this program to compile.
It has something to do with brackets in the wrong place(s), but I just can't find what's wrong.
Help, anyone?

#include <iostream>
#include <string>
#include <sstream>
#include <conio.h>
#include <ctime>
#include <iomanip>
#include "iodos.h"

using namespace std;

// Funktionsprototyper --------------------------------------------------------------------------
void showMenu();
void diceSim();
void countDays();
void teleTaxa();
// Slut på funktionsprototyper ------------------------------------------------------------------

int main()
{
  dos_console(850);

// Funktionsdefinition ------------------------------------------------------------------------------
// Namn:    showMenu
// Uppgift: Visar huvudmenyn
// Indata:  -
// Utdata:  -
// Slut på funktionsdefinition ----------------------------------------------------------------------

  bool again = true;
  do 
  {
     showMenu();						// Visa menyalternativ 
     
	 cout << "Var vänlig och välj ett underprogram:" << endl;
	 cout << endl;
	 cout << "1: Simulera tärningskast" << endl;
	 cout << "2: Räkna dagar"           << endl;
	 cout << "3: Räkna ut telekostnad"  << endl;
	 cout << "4: Avsluta"               << endl;

	 char ch = _getch();				// Användaren gör sitt val 
     switch(ch) 
     {									// Kör valt delprogram 
        case '1': diceSim(); 
                  break; 
        case '2': countDays(); 
                  break; 
		case '3': teleTaxa();
		
		case '4':						// Avsluta med '4'
        case 'a':						// Avsluta med 'a'
        case 'A':						// Avsluta med 'A'
        case char(27): again = false;	// Avsluta med 'ESC'
	 }       
  
  }while(again);
  
  return 0;

}
// Slut på menyprogrammet

// Funktionsdefinition ------------------------------------------------------------------------------
// Namn:    diceSim
// Uppgift: Simulerar tärningskast
// Indata:  -
// Utdata:  -
// Slut på funktionsdefinition ----------------------------------------------------------------------

  void diceSim();
{
  int frekvens[7] = {0, 0, 0, 0, 0, 0, 0};
  int resultat;
  int antalKast;                      

  cout << "VÄLKOMMEN TILL TÄRNINGSSIMULATORN!" << endl;				// Huvudrubrik
  cout << "==================================" << endl << endl; 
  cout << "Detta program simulerar det antal tärningskast som anges av användaren." << endl;
  cout << "Var god mata in antalet kast (1-1000): ";
  cin >> antalKast;													// Inmatning för angivna kast

  while (antalKast <= 0 || antalKast > 1000)						// Kontrollerar att värdet = 1-1000
  {
	cout << "Felaktig inmatning! Värdet måste vara 1 - 1000! Försök igen: ";
	cin >> antalKast;
  }
  cout << endl;

  srand((unsigned) time(0));										// Använder systemklockan som slumpgenerator

  // Slumpar antalet kast som angivits och uppdaterar tabellen
  for (int i = 1; i <= antalKast; i++)
  {
    resultat = rand()%6 + 1;										// Får ett slumpmässigt tal 1-6
    frekvens[resultat]++;
  }

  // Skriver ut tabellen "frekvens"
  for (resultat = 1; resultat <= 6; resultat++)
  cout << resultat << ": " << setw(7) << frekvens[resultat] << endl;
  cout << endl;
  cout << "===========================================" << endl;
  cout << endl;
  
  // Skriver ut tabellen "relativ frekvens"
  cout << fixed << setprecision(2);
  cout << "Relativ frekvens för ettor: "
       << setw(5) << static_cast<float>(frekvens[1])/static_cast<float>(antalKast) << endl;
    
  cout << fixed << setprecision(2);
  cout << "Relativ frekvens för tvåor: "
       << setw(5) << static_cast<float>(frekvens[2])/static_cast<float>(antalKast) << endl;
	  
  cout << fixed << setprecision(2);
  cout << "Relativ frekvens för treor: "
       << setw(5) << static_cast<float>(frekvens[3])/static_cast<float>(antalKast) << endl;
	
  cout << fixed << setprecision(2);
  cout << "Relativ frekvens för fyror: "
       << setw(5) << static_cast<float>(frekvens[4])/static_cast<float>(antalKast) << endl;

  cout << fixed << setprecision(2);
  cout << "Relativ frekvens för femmor: "
       << setw(4) << static_cast<float>(frekvens[5])/static_cast<float>(antalKast) << endl;

  cout << fixed << setprecision(2);
  cout << "Relativ frekvens för sexor: "
       << setw(5) << static_cast<float>(frekvens[6])/static_cast<float>(antalKast) << endl;

  cout << endl;

}
// Slut på delprogram 1

//--------------------------------------------------------------------------------------------------
// Funktionsprototyper 
//--------------------------------------------------------------------------------------------------

bool leapYear(int year);
int daysInMonth(int month, int year);
int daysFrom1900(int year, int month, int day);
int days(string d1, string d2);

//--------------------------------------------------------------------------------------------------
// Huvudprogram 
//--------------------------------------------------------------------------------------------------
void countDays();
{  
  dos_console(850);
  bool restart;                                                 // Avgör om programmet skall upprepas
  do
  { 
    string startDate, endDate;
    system("cls");                                              // Rensar skärmen
    cout << " Detta program beräknar antalet dagar mellan två datum (tidigast 1/1 1900)" << endl;
    cout << " =========================================================================" << endl << endl;
    cout << " Ange startdatum (ÅÅÅÅMMDD): ";
    cin >> startDate;                                           // Inmatning till variabeln startDate
    cout << " Ange slutdatum (ÅÅÅÅMMDD) : ";
    cin >> endDate;                                             // Inmatning till variabeln endDate
    cout << endl;

    // Anropar funktionen days och skriver ut antalet dagar
    cout << " Antal dygn emellan = " << days (startDate, endDate) << endl << endl;

	cout << " Vill du göra en ny beräkning? (j/n)" << endl;
    char ch;
    do
    {
      ch = _getch();
      ch = toupper(ch);                                         // Fungerar med versaler
      if (ch == 'J')                                 
	    restart = true;                                                                                                                   
      if (ch == 'N')                   
        restart = false;
	}while (!(ch == 'J' || ch == 'N'));

  }while (restart);                                             // Upprepar programmet om sant
}
//--------------------------------------------------------------------------------------------------
// Funktionsdefinitioner
//--------------------------------------------------------------------------------------------------
// Namn: leapYear
// Uppgift: Kontrollerar skottår
// Indata: Årtal (heltal)
// Utdata: true/false
//--------------------------------------------------------------------------------------------------
bool leapYear(int year)
{  // Beräkning av skottår
   return year%4 == 0 && (year%100 != 0 || year%400 == 0);
}
//--------------------------------------------------------------------------------------------------
// Namn: daysInMonth
// Uppgift: Beräkna antalet dagar i en månad
// Indata: Årtal (heltal)
//         Månadsnummer (heltal)
// Utdata: Antal dagar i respektive månad, med hänsyn till skottår (heltal)
//--------------------------------------------------------------------------------------------------
int daysInMonth(int month, int year)
{
  // Innehållet 0-12 i vektorn motsvararar antalet dagar i varje månad
  int daysInMonth[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

  if (leapYear(year))         // Anropar funktionen leapYear
     daysInMonth[2] = 29;     // Februari får 29 dagar om skottår

  return daysInMonth[month];
}
//--------------------------------------------------------------------------------------------------
// Namn: daysFrom1900
// Uppgift: Beräkna antalet dygn från 31/12 1899 fram till ett givet datum
// Indata: År (heltal), månad (heltal), dag (heltal)
// Utdata: Antal dygn från 31/12 1899 till angivet datum (heltal)
//--------------------------------------------------------------------------------------------------
int daysFrom1900(int year, int month, int day)
{ 
  int yearsFrom1900 = 0;
  int daysFrom1900  = 0;
  int monthsDays    = 0;

  // Ökar på dagarna för året fram till angivet år
  for (yearsFrom1900 = 1900; yearsFrom1900 < year; yearsFrom1900++)
  {
    if (leapYear(yearsFrom1900))                        // Anropar funktionen leapYear
	  daysFrom1900 += 366;
	else
	  daysFrom1900 += 365;
  }

  // Ökar på dagarna för månaderna fram till angiven månad
  for (monthsDays = 0; monthsDays < month; monthsDays++)
  {
    daysFrom1900 += daysInMonth(monthsDays, year);      // Anropar funktionen "daysInMonth"
  }

  // Ökar på dagen för månaden och returnerar totalsumma
  return daysFrom1900 + day;
}
//--------------------------------------------------------------------------------------------------
// Namn: days
// Uppgift: Beräkna antalet dygn mellan två datum
// Indata: Startdatum som en sträng på formen ÅÅÅÅMMDD
//         Slutdatum som en sträng på formen ÅÅÅÅMMDD
// Utdata: Antalet dygn från startdatum till slutdatum (heltal)
//--------------------------------------------------------------------------------------------------
int days(string d1, string d2)
{ 
  // Plockar ut årtal, månad och dag med substring ur sträng d1 och d2
  string d1YearStr  = d1.substr(0,4);
  string d1MonthStr = d1.substr(4,2);
  string d1DayStr   = d1.substr(6,2);
  string d2YearStr  = d2.substr(0,4);
  string d2MonthStr = d2.substr(4,2);
  string d2DayStr   = d2.substr(6,2);

  // Omvandlar strängar till heltal
  int d1Year  = atoi(d1YearStr.c_str());
  int d1Month = atoi(d1MonthStr.c_str());
  int d1Day   = atoi(d1DayStr.c_str());
  int d2Year  = atoi(d2YearStr.c_str());
  int d2Month = atoi(d2MonthStr.c_str());
  int d2Day   = atoi(d2DayStr.c_str());

  // Anropar funktionen "daysFrom1900", returnerar sedan antalet dagar mellan datumen
  return daysFrom1900(d2Year, d2Month, d2Day) - daysFrom1900(d1Year, d1Month, d1Day);
}
// Slut på delprogram 2




//--------------------------------------------------------------------------------------------------
// Funktionsprototyper 
//--------------------------------------------------------------------------------------------------

float controlFunction(string t1, string t2);
float totalCosts(int t1Hour, int t1Minute, int t2Hour, int t2Minute);
bool dayDiscount(int minute);

//--------------------------------------------------------------------------------------------------
// Huvudprogram 
//--------------------------------------------------------------------------------------------------

void teleTaxa();
{
    dos_console();
    
    bool restart;                                                 // Avgör om programmet skall upprepas
    
    cout << endl;
	cout << " RingPling 2004 AB" << endl;                         // Huvudrubrik
    cout << " =================" << endl << endl;
	cout << " Beräknar samtalskostnad" << endl <<endl;

	do
	{
	  string start, stop;                                        // Sträng-variabler
	  cout << endl;
	  cout << " Ange starttid (hh:mm): ";
      cin >> start;                                              // Inmatning till start
	  cout << " Ange sluttid (hh:mm) : ";
      cin >> stop;                                               // Inmatning till stop
      cout << endl;

      // Anropar funktionen "controlFunction" och skriver ut totalkostnaden
	  cout << endl;
	  cout << " Total samtalskostnad: "
	  << fixed << setprecision(2)
	  << controlFunction(start, stop) <<" kr" << endl << endl;

	  // Frågar om omstart
	  cout << " Ny beräkning? (j/n) ";
      char ch;
      do
      {
        ch = _getch();                                          // Tar emot ett tecken till "char ch"
        ch = toupper(ch);                                       // Accepterar versaler
        if (ch == 'J')                                 
	      restart = true;                                                                                                                   
        if (ch == 'N')                   
          restart = false;
		system("cls");
	  }while (!(ch == 'J' || ch == 'N'));

    }while (restart);                                            // Upprepar do...while
}
//--------------------------------------------------------------------------------------------------
// Funktionsdefinitioner
//--------------------------------------------------------------------------------------------------
// Namn: controlFunction
// Uppgift: Kontrollerar start- och stopptid
// Indata: Starttid som sträng på formen (hh:mm)
//         Stopptid som sträng på formen (hh:mm)
// Utdata: Returnerar totalkostnaden (flyttal)
//--------------------------------------------------------------------------------------------------
float controlFunction(string t1, string t2)
{ 
  // Variabler för kontroll av inmatning samt tid
  bool timeOK = true;
  int t1Hour = 0;
  int t1Minute = 0;
  int t2Hour = 0;
  int t2Minute = 0;

  do
  {
    if (!timeOK)                                // Utförs vid felaktig inmatning
	{
	  cout << " Felaktig inmatning!" << endl;
	  cout << " Ange starttid (hh:mm): ";
	  cin >> t1;
	  cout << " Ange sluttid (hh:mm) : ";
      cin >> t2;
	  timeOK = true;
	}

    if (!(t1[2] == ':' && t2[2] == ':'))        // Kontrollerar att rätt tidsavgränsare används
      timeOK = false;
    
	// Skriver över ':' med mellanslag
    t1[2] = ' ';
    t2[2] = ' ';

    // Konverterar siffror i sträng till tal
    istringstream start(t1);
      start >> t1Hour >> t1Minute;
    istringstream stop(t2);
      stop >> t2Hour >> t2Minute;

    // Kontrollerar att timmar och minuter är ok
    // Kontrolleras att stopptiden är större än starttiden
    if (t1Hour < 0 || t1Hour > 23)
      timeOK = false;
	if (t2Hour < 0 || t2Hour > 23)
      timeOK = false;
    if (t1Minute < 0 || t1Minute > 59)
      timeOK = false;
	if (t2Minute < 0 || t2Minute > 59)
      timeOK = false;
    if ((t2Hour *60 + t2Minute) < (t1Hour *60 + t1Minute))
	  timeOK = false;
  }while (!timeOK);                             // Upprepas ifall tid inte är ok

  // Anropar funktionen "totalCosts" och returnerar talet med totalkostnaden
  return totalCosts (t1Hour, t1Minute, t2Hour, t2Minute);  
}
//--------------------------------------------------------------------------------------------------
// Namn: totalCosts
// Uppgift: Beräknar den totala kostnaden
// Indata: Starttid, timma (heltal)
//         Starttid, minut (heltal) 
//         Stopptid, timma (heltal
//         Stopptid, minut (heltal)
// Utdata: Returnerar totalkostnaden med moms plus eventuella rabatter (flyttal)
//--------------------------------------------------------------------------------------------------
float totalCosts(int t1Hour, int t1Minute, int t2Hour, int t2Minute)
{
  int totalMinutes = 0;
  double minutePrice = 0;
  double totalCost = 0;
  const double MOMS = 0.25;                        // Moms
  const double FULL_PRICE = 4;                     // Fullpristaxa
  const double DAY_DISCOUNT = 0.65;               // Rabatt för samtal före 8:00 och efter 18:30
  const double LONG_DISCOUNT = 0.15;              // Rabatt för samtal längre än 30 min 

  // Antar att dygnet enbart räknas i minuter, lägger på taxa till variabeln "minutePrice"
  for (totalMinutes = t1Hour *60 + t1Minute; totalMinutes < t2Hour *60 + t2Minute; totalMinutes++)
  {
    if (dayDiscount(totalMinutes))                // Anropar funktionen "dayDiscount"
	  minutePrice += (FULL_PRICE * DAY_DISCOUNT);
	else
	  minutePrice += FULL_PRICE; 
  }
  
  minutePrice += (minutePrice *MOMS);              // Adderar momsen
  totalCost = minutePrice;                        // Tilldelar totalpriset till en egen variabel
  
  // Ifall samtalet är mer än 30 min dras rabatten av från totalkostnaden
  // Totala minuterna för stopptid - totala minuterna för starttid
  if ((t2Hour *60 + t2Minute) - (t1Hour *60 + t1Minute) >30)
    totalCost -= (totalCost *LONG_DISCOUNT); 

  return totalCost;                        // Returnerar totalkostnaden
}
//--------------------------------------------------------------------------------------------------
// Namn: dayDiscount
// Uppgift: Kontrollerar ifall dygnsrabatt för given minut
// Indata: Minut för dygnet (heltal)
// Utdata: Returnerar true ifall dygnsrabatt, annars false
//--------------------------------------------------------------------------------------------------
bool dayDiscount(int minute)
{ 
  // Deklarerar konstanta heltal för rabatterade timmar
  const int EIGHT_AM = 480;
  const int EIGHT_THYRTY_PM = 1110; 

  // Returnerar true ifall minuterna är före 08:00 eller efter 18:30
  // 1 dygn = 24 * 60 minuter = 1440 minuter)
  return ((minute > 0 && minute< EIGHT_AM) || (minute > EIGHT_THYRTY_PM && minute < 1440)); 
}

Recommended Answers

All 13 Replies

Some of your function definitions have a rogue semicolon before the opening brace. Clearly you copy-pasted the declaration and forgot to remove the semicolon.

Some of your function definitions have a rogue semicolon before the opening brace. Clearly you copy-pasted the declaration and forgot to remove the semicolon.

Could you please be more specific? I can't seem to find the problem you mention.
Thanks.

Line 70 and 71:

void diceSim();
{

See the semicolon? It shouldn't be there. Look for a similar pattern and fix it on the other function definitions.

Right, now that I've gotten rid of the rogue semicolons, I have what's below.
Still won't compile though.
Apparently the brace on line 31 is the beginning of the problem.
My compiler says this:

1>c:\users\peter\documents\programvaruteknik\lab2\uppgift 4\uppgift 4\uppgift 4.cpp(31): error C2059: syntax error : '{'
1>c:\users\peter\documents\programvaruteknik\lab2\uppgift 4\uppgift 4\uppgift 4.cpp(31): error C2143: syntax error : missing ';' before '{'
1>c:\users\peter\documents\programvaruteknik\lab2\uppgift 4\uppgift 4\uppgift 4.cpp(34): error C2146: syntax error : missing ';' before identifier 'cout'
1>c:\users\peter\documents\programvaruteknik\lab2\uppgift 4\uppgift 4\uppgift 4.cpp(423): warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data

#include <iostream>
#include <string>
#include <sstream>
#include <conio.h>
#include <ctime>
#include <iomanip>
#include "iodos.h"

using namespace std;

// Funktionsprototyper --------------------------------------------------------------------------
void showMenu();
void diceSim();
void countDays();
void teleTaxa();
// Slut på funktionsprototyper ------------------------------------------------------------------

int main()
{
  dos_console(850);

// Funktionsdefinition ------------------------------------------------------------------------------
// Namn:    showMenu
// Uppgift: Visar huvudmenyn
// Indata:  -
// Utdata:  -
// Slut på funktionsdefinition ----------------------------------------------------------------------

  bool again = true;
  do;
  {
     showMenu()							// Visa menyalternativ 
     
	 cout << "Var vänlig och välj ett underprogram:" << endl;
	 cout << endl;
	 cout << "1: Simulera tärningskast" << endl;
	 cout << "2: Räkna dagar"           << endl;
	 cout << "3: Räkna ut telekostnad"  << endl;
	 cout << "4: Avsluta"               << endl;

	 char ch = _getch();				// Användaren gör sitt val 
     switch(ch) 
     {									// Kör valt delprogram 
        case '1': diceSim(); 
                  break; 
        case '2': countDays(); 
                  break; 
		case '3': teleTaxa();
		
		case '4':						// Avsluta med '4'
        case 'a':						// Avsluta med 'a'
        case 'A':						// Avsluta med 'A'
        case char(27): again = false;	// Avsluta med 'ESC'
	 }       
  
  }while(again);
  
  return 0;

}
// Slut på menyprogrammet

// Funktionsdefinition ------------------------------------------------------------------------------
// Namn:    diceSim
// Uppgift: Simulerar tärningskast
// Indata:  -
// Utdata:  -
// Slut på funktionsdefinition ----------------------------------------------------------------------

  void diceSim()
{
  int frekvens[7] = {0, 0, 0, 0, 0, 0, 0};
  int resultat;
  int antalKast;                      

  cout << "VÄLKOMMEN TILL TÄRNINGSSIMULATORN!" << endl;				// Huvudrubrik
  cout << "==================================" << endl << endl; 
  cout << "Detta program simulerar det antal tärningskast som anges av användaren." << endl;
  cout << "Var god mata in antalet kast (1-1000): ";
  cin >> antalKast;													// Inmatning för angivna kast

  while (antalKast <= 0 || antalKast > 1000)						// Kontrollerar att värdet = 1-1000
  {
	cout << "Felaktig inmatning! Värdet måste vara 1 - 1000! Försök igen: ";
	cin >> antalKast;
  }
  cout << endl;

  srand((unsigned) time(0));										// Använder systemklockan som slumpgenerator

  // Slumpar antalet kast som angivits och uppdaterar tabellen
  for (int i = 1; i <= antalKast; i++)
  {
    resultat = rand()%6 + 1;										// Får ett slumpmässigt tal 1-6
    frekvens[resultat]++;
  }

  // Skriver ut tabellen "frekvens"
  for (resultat = 1; resultat <= 6; resultat++)
  cout << resultat << ": " << setw(7) << frekvens[resultat] << endl;
  cout << endl;
  cout << "===========================================" << endl;
  cout << endl;
  
  // Skriver ut tabellen "relativ frekvens"
  cout << fixed << setprecision(2);
  cout << "Relativ frekvens för ettor: "
       << setw(5) << static_cast<float>(frekvens[1])/static_cast<float>(antalKast) << endl;
    
  cout << fixed << setprecision(2);
  cout << "Relativ frekvens för tvåor: "
       << setw(5) << static_cast<float>(frekvens[2])/static_cast<float>(antalKast) << endl;
	  
  cout << fixed << setprecision(2);
  cout << "Relativ frekvens för treor: "
       << setw(5) << static_cast<float>(frekvens[3])/static_cast<float>(antalKast) << endl;
	
  cout << fixed << setprecision(2);
  cout << "Relativ frekvens för fyror: "
       << setw(5) << static_cast<float>(frekvens[4])/static_cast<float>(antalKast) << endl;

  cout << fixed << setprecision(2);
  cout << "Relativ frekvens för femmor: "
       << setw(4) << static_cast<float>(frekvens[5])/static_cast<float>(antalKast) << endl;

  cout << fixed << setprecision(2);
  cout << "Relativ frekvens för sexor: "
       << setw(5) << static_cast<float>(frekvens[6])/static_cast<float>(antalKast) << endl;

  cout << endl;

}
// Slut på delprogram 1

//--------------------------------------------------------------------------------------------------
// Funktionsprototyper 
//--------------------------------------------------------------------------------------------------

bool leapYear(int year);
int daysInMonth(int month, int year);
int daysFrom1900(int year, int month, int day);
int days(string d1, string d2);

//--------------------------------------------------------------------------------------------------
// Huvudprogram 
//--------------------------------------------------------------------------------------------------
void countDays()
{  
  dos_console(850);
  bool restart;                                                 // Avgör om programmet skall upprepas
  do
  { 
    string startDate, endDate;
    system("cls");                                              // Rensar skärmen
    cout << " Detta program beräknar antalet dagar mellan två datum (tidigast 1/1 1900)" << endl;
    cout << " =========================================================================" << endl << endl;
    cout << " Ange startdatum (ÅÅÅÅMMDD): ";
    cin >> startDate;                                           // Inmatning till variabeln startDate
    cout << " Ange slutdatum (ÅÅÅÅMMDD) : ";
    cin >> endDate;                                             // Inmatning till variabeln endDate
    cout << endl;

    // Anropar funktionen days och skriver ut antalet dagar
    cout << " Antal dygn emellan = " << days (startDate, endDate) << endl << endl;

	cout << " Vill du göra en ny beräkning? (j/n)" << endl;
    char ch;
    do
    {
      ch = _getch();
      ch = toupper(ch);                                         // Fungerar med versaler
      if (ch == 'J')                                 
	    restart = true;                                                                                                                   
      if (ch == 'N')                   
        restart = false;
	}while (!(ch == 'J' || ch == 'N'));

  }while (restart);                                             // Upprepar programmet om sant
}
//--------------------------------------------------------------------------------------------------
// Funktionsdefinitioner
//--------------------------------------------------------------------------------------------------
// Namn: leapYear
// Uppgift: Kontrollerar skottår
// Indata: Årtal (heltal)
// Utdata: true/false
//--------------------------------------------------------------------------------------------------
bool leapYear(int year)
{  // Beräkning av skottår
   return year%4 == 0 && (year%100 != 0 || year%400 == 0);
}
//--------------------------------------------------------------------------------------------------
// Namn: daysInMonth
// Uppgift: Beräkna antalet dagar i en månad
// Indata: Årtal (heltal)
//         Månadsnummer (heltal)
// Utdata: Antal dagar i respektive månad, med hänsyn till skottår (heltal)
//--------------------------------------------------------------------------------------------------
int daysInMonth(int month, int year)
{
  // Innehållet 0-12 i vektorn motsvararar antalet dagar i varje månad
  int daysInMonth[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

  if (leapYear(year))         // Anropar funktionen leapYear
     daysInMonth[2] = 29;     // Februari får 29 dagar om skottår

  return daysInMonth[month];
}
//--------------------------------------------------------------------------------------------------
// Namn: daysFrom1900
// Uppgift: Beräkna antalet dygn från 31/12 1899 fram till ett givet datum
// Indata: År (heltal), månad (heltal), dag (heltal)
// Utdata: Antal dygn från 31/12 1899 till angivet datum (heltal)
//--------------------------------------------------------------------------------------------------
int daysFrom1900(int year, int month, int day)
{ 
  int yearsFrom1900 = 0;
  int daysFrom1900  = 0;
  int monthsDays    = 0;

  // Ökar på dagarna för året fram till angivet år
  for (yearsFrom1900 = 1900; yearsFrom1900 < year; yearsFrom1900++)
  {
    if (leapYear(yearsFrom1900))                        // Anropar funktionen leapYear
	  daysFrom1900 += 366;
	else
	  daysFrom1900 += 365;
  }

  // Ökar på dagarna för månaderna fram till angiven månad
  for (monthsDays = 0; monthsDays < month; monthsDays++)
  {
    daysFrom1900 += daysInMonth(monthsDays, year);      // Anropar funktionen "daysInMonth"
  }

  // Ökar på dagen för månaden och returnerar totalsumma
  return daysFrom1900 + day;
}
//--------------------------------------------------------------------------------------------------
// Namn: days
// Uppgift: Beräkna antalet dygn mellan två datum
// Indata: Startdatum som en sträng på formen ÅÅÅÅMMDD
//         Slutdatum som en sträng på formen ÅÅÅÅMMDD
// Utdata: Antalet dygn från startdatum till slutdatum (heltal)
//--------------------------------------------------------------------------------------------------
int days(string d1, string d2)
{ 
  // Plockar ut årtal, månad och dag med substring ur sträng d1 och d2
  string d1YearStr  = d1.substr(0,4);
  string d1MonthStr = d1.substr(4,2);
  string d1DayStr   = d1.substr(6,2);
  string d2YearStr  = d2.substr(0,4);
  string d2MonthStr = d2.substr(4,2);
  string d2DayStr   = d2.substr(6,2);

  // Omvandlar strängar till heltal
  int d1Year  = atoi(d1YearStr.c_str());
  int d1Month = atoi(d1MonthStr.c_str());
  int d1Day   = atoi(d1DayStr.c_str());
  int d2Year  = atoi(d2YearStr.c_str());
  int d2Month = atoi(d2MonthStr.c_str());
  int d2Day   = atoi(d2DayStr.c_str());

  // Anropar funktionen "daysFrom1900", returnerar sedan antalet dagar mellan datumen
  return daysFrom1900(d2Year, d2Month, d2Day) - daysFrom1900(d1Year, d1Month, d1Day);
}
// Slut på delprogram 2




//--------------------------------------------------------------------------------------------------
// Funktionsprototyper 
//--------------------------------------------------------------------------------------------------

float controlFunction(string t1, string t2);
float totalCosts(int t1Hour, int t1Minute, int t2Hour, int t2Minute);
bool dayDiscount(int minute);

//--------------------------------------------------------------------------------------------------
// Huvudprogram 
//--------------------------------------------------------------------------------------------------

void teleTaxa()
{
    dos_console();
    
    bool restart;                                                 // Avgör om programmet skall upprepas
    
    cout << endl;
	cout << " RingPling 2004 AB" << endl;                         // Huvudrubrik
    cout << " =================" << endl << endl;
	cout << " Beräknar samtalskostnad" << endl <<endl;

	do
	{
	  string start, stop;                                        // Sträng-variabler
	  cout << endl;
	  cout << " Ange starttid (hh:mm): ";
      cin >> start;                                              // Inmatning till start
	  cout << " Ange sluttid (hh:mm) : ";
      cin >> stop;                                               // Inmatning till stop
      cout << endl;

      // Anropar funktionen "controlFunction" och skriver ut totalkostnaden
	  cout << endl;
	  cout << " Total samtalskostnad: "
	  << fixed << setprecision(2)
	  << controlFunction(start, stop) <<" kr" << endl << endl;

	  // Frågar om omstart
	  cout << " Ny beräkning? (j/n) ";
      char ch;
      do
      {
        ch = _getch();                                          // Tar emot ett tecken till "char ch"
        ch = toupper(ch);                                       // Accepterar versaler
        if (ch == 'J')                                 
	      restart = true;                                                                                                                   
        if (ch == 'N')                   
          restart = false;
		system("cls");
	  }while (!(ch == 'J' || ch == 'N'));

    }while (restart);                                            // Upprepar do...while
}
//--------------------------------------------------------------------------------------------------
// Funktionsdefinitioner
//--------------------------------------------------------------------------------------------------
// Namn: controlFunction
// Uppgift: Kontrollerar start- och stopptid
// Indata: Starttid som sträng på formen (hh:mm)
//         Stopptid som sträng på formen (hh:mm)
// Utdata: Returnerar totalkostnaden (flyttal)
//--------------------------------------------------------------------------------------------------
float controlFunction(string t1, string t2)
{ 
  // Variabler för kontroll av inmatning samt tid
  bool timeOK = true;
  int t1Hour = 0;
  int t1Minute = 0;
  int t2Hour = 0;
  int t2Minute = 0;

  do
  {
    if (!timeOK)                                // Utförs vid felaktig inmatning
	{
	  cout << " Felaktig inmatning!" << endl;
	  cout << " Ange starttid (hh:mm): ";
	  cin >> t1;
	  cout << " Ange sluttid (hh:mm) : ";
      cin >> t2;
	  timeOK = true;
	}

    if (!(t1[2] == ':' && t2[2] == ':'))        // Kontrollerar att rätt tidsavgränsare används
      timeOK = false;
    
	// Skriver över ':' med mellanslag
    t1[2] = ' ';
    t2[2] = ' ';

    // Konverterar siffror i sträng till tal
    istringstream start(t1);
      start >> t1Hour >> t1Minute;
    istringstream stop(t2);
      stop >> t2Hour >> t2Minute;

    // Kontrollerar att timmar och minuter är ok
    // Kontrolleras att stopptiden är större än starttiden
    if (t1Hour < 0 || t1Hour > 23)
      timeOK = false;
	if (t2Hour < 0 || t2Hour > 23)
      timeOK = false;
    if (t1Minute < 0 || t1Minute > 59)
      timeOK = false;
	if (t2Minute < 0 || t2Minute > 59)
      timeOK = false;
    if ((t2Hour *60 + t2Minute) < (t1Hour *60 + t1Minute))
	  timeOK = false;
  }while (!timeOK);                             // Upprepas ifall tid inte är ok

  // Anropar funktionen "totalCosts" och returnerar talet med totalkostnaden
  return totalCosts (t1Hour, t1Minute, t2Hour, t2Minute);  
}
//--------------------------------------------------------------------------------------------------
// Namn: totalCosts
// Uppgift: Beräknar den totala kostnaden
// Indata: Starttid, timma (heltal)
//         Starttid, minut (heltal) 
//         Stopptid, timma (heltal
//         Stopptid, minut (heltal)
// Utdata: Returnerar totalkostnaden med moms plus eventuella rabatter (flyttal)
//--------------------------------------------------------------------------------------------------
float totalCosts(int t1Hour, int t1Minute, int t2Hour, int t2Minute)
{
  int totalMinutes = 0;
  double minutePrice = 0;
  double totalCost = 0;
  const double MOMS = 0.25;                        // Moms
  const double FULL_PRICE = 4;                     // Fullpristaxa
  const double DAY_DISCOUNT = 0.65;               // Rabatt för samtal före 8:00 och efter 18:30
  const double LONG_DISCOUNT = 0.15;              // Rabatt för samtal längre än 30 min 

  // Antar att dygnet enbart räknas i minuter, lägger på taxa till variabeln "minutePrice"
  for (totalMinutes = t1Hour *60 + t1Minute; totalMinutes < t2Hour *60 + t2Minute; totalMinutes++)
  {
    if (dayDiscount(totalMinutes))                // Anropar funktionen "dayDiscount"
	  minutePrice += (FULL_PRICE * DAY_DISCOUNT);
	else
	  minutePrice += FULL_PRICE; 
  }
  
  minutePrice += (minutePrice *MOMS);              // Adderar momsen
  totalCost = minutePrice;                        // Tilldelar totalpriset till en egen variabel
  
  // Ifall samtalet är mer än 30 min dras rabatten av från totalkostnaden
  // Totala minuterna för stopptid - totala minuterna för starttid
  if ((t2Hour *60 + t2Minute) - (t1Hour *60 + t1Minute) >30)
    totalCost -= (totalCost *LONG_DISCOUNT); 

  return totalCost;                        // Returnerar totalkostnaden
}
//--------------------------------------------------------------------------------------------------
// Namn: dayDiscount
// Uppgift: Kontrollerar ifall dygnsrabatt för given minut
// Indata: Minut för dygnet (heltal)
// Utdata: Returnerar true ifall dygnsrabatt, annars false
//--------------------------------------------------------------------------------------------------
bool dayDiscount(int minute)
{ 
  // Deklarerar konstanta heltal för rabatterade timmar
  const int EIGHT_AM = 480;
  const int EIGHT_THYRTY_PM = 1110; 

  // Returnerar true ifall minuterna är före 08:00 eller efter 18:30
  // 1 dygn = 24 * 60 minuter = 1440 minuter)
  return ((minute > 0 && minute< EIGHT_AM) || (minute > EIGHT_THYRTY_PM && minute < 1440)); 
}

Do you see the numbers in parentheses in the errors? Those are Line numbers. The first three errors are flagging Lines 31 and 34. Here are lines 29-34 of your code, for reference:

/*29*/  bool again = true;
/*30*/  do;
/*31*/  {
/*32*/     showMenu()							// Visa menyalternativ
/*33*/
/*34*/ 	 cout << "Var vänlig och välj ett underprogram:" << endl;

What's wrong here? Where did the semi-colon after the do on Line 30 come from? It wasn't there before... Why would you add it?

I have faith that you can figure out the last error. It's pretty self-explanatory.

Do you see the numbers in parentheses in the errors? Those are Line numbers. The first three errors are flagging Lines 31 and 34. Here are lines 29-34 of your code, for reference:

/*29*/  bool again = true;
/*30*/  do;
/*31*/  {
/*32*/     showMenu()							// Visa menyalternativ
/*33*/
/*34*/ 	 cout << "Var vänlig och välj ett underprogram:" << endl;

What's wrong here? Where did the semi-colon after the do on Line 30 come from? It wasn't there before... Why would you add it?

I have faith that you can figure out the last error. It's pretty self-explanatory.

You're absolutely right, of course. I really don't know how that semicolon ended up there. I'll go through the whole thing again and see if I can find the last little thingy.

Thanks a million!

Here's a little hint regarding the fourth error:
A float and a double are both floating-point dataTypes, but a double has higher precision and a larger capacity.

Nope, it still won't work. I am probably the dumbest guy around just now, but my compiler says there is a semicolon missing before the cout. If I put one in after showMenu(), it says:

error LNK2019: unresolved external symbol "void __cdecl showMenu(void)" (?showMenu@@YAXXZ) referenced in function _main

Here are lines 29-34 again:

bool again = true;
  do
  {
     showMenu()							// Visa menyalternativ 
     
	 cout << "Var vänlig och välj ett underprogram:" << endl;

PS: I know about the fourth problem, I just don't know how to go about it.

The semi-colon must be there.

The error you are receiving is a linker error, not a compiler error.

This type of error means that the code compiled successfully, but you don't have a recognizable implementation for the function showMenu().

I went back through your code and looked at it more closely. This is your main():

int main()
{
  dos_console(850);
 
// Funktionsdefinition ------------------------------------------------------------------------------
// Namn:    showMenu
// Uppgift: Visar huvudmenyn
// Indata:  -
// Utdata:  -
// Slut på funktionsdefinition ----------------------------------------------------------------------
 
  bool again = true;
  do;
  {
     showMenu()							// Visa menyalternativ 
 
	 cout << "Var vänlig och välj ett underprogram:" << endl;
	 cout << endl;
	 cout << "1: Simulera tärningskast" << endl;
	 cout << "2: Räkna dagar"           << endl;
	 cout << "3: Räkna ut telekostnad"  << endl;
	 cout << "4: Avsluta"               << endl;
 
	 char ch = _getch();				// Användaren gör sitt val 
     switch(ch) 
     {									// Kör valt delprogram 
        case '1': diceSim(); 
                  break; 
        case '2': countDays(); 
                  break; 
		case '3': teleTaxa();
 
		case '4':						// Avsluta med '4'
        case 'a':						// Avsluta med 'a'
        case 'A':						// Avsluta med 'A'
        case char(27): again = false;	// Avsluta med 'ESC'
	 }       
 
  }while(again);
 
  return 0;
 
}

It seems that you are attempting to implement showMenu() inside of main(), which is a big no-no.

I can't give you a solution to this because I don't know how much of the code you intend to be part of showMenu() and how much should be in main(). I will say though, that you'll have to break some of this code out into a definition for showMenu().

I don't quite understand what your last remark means (remember, I'm pretty much a total rookie at this), but I will explain what I want the program to do:

1. Display the Menu as in showMenu(), giving the option to select:
a) diceSim
b) countDays
c) RingPling 2004 (a program to calculate the minute price of a phone call)
d) end the program with 'a', 'A' or Esc.

You don't have to be extremely experienced to understand my remark, even a "rookie" should be able to understand it.

The build process is made up of multiple steps. The 2 most important are compiling and linking.

When you compile your code (called "source code"), a program called a "compiler" checks its syntax and translates it into code that the computer can understand. This new code is commonly called "object code".

If compilation completes successfully, another program called a "linker" works its way through the generated object code adding to, and rearranging, it as necessary to produce a runnable program. If the linker can't find a piece of object code that it needs, it throws an error.

The error you are experiencing is from the linker NOT the compiler. It can't find the object code that it needs for showMenu() because you haven't written the source code for the compiler to generate it from. So far, you've only declared and attempted to call it.

I'm sorry, but I must be an idiot. I still don't know what to do.
I'll have to try something else.
Thanks for your time anyway, Fbody!

>>I still don't know what to do.


You need to write this function:

void showMenu()

or you need to remove all traces of it from your program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.