Question

Getting this error. [Error] expected ';' after class definition #include <iostream> #include <cstdlib> #include <ctime> #include...

Getting this error. [Error] expected ';' after class definition

#include <iostream>

#include <cstdlib>

#include <ctime>

#include <conio.h>

using namespace std;

int sum=0;

class Coin

{

int sideUp;

public:

Coin(int value)

{

toss(value);

};

void toss(int value);

}

void Coin::toss(int value)

{

if(rand() %100<=50)

{

sum+=value;

cout<<"\n You got a head. Value "<<value<<" added!!";

}

else

{

cout<<"\n You got a tail. No value added";

}

}

int main()

{

int temp;

cout<<"\n Quarter = 25 cents\n Dime = 10 cents \n Nickel = 5 cents\n\n";

cout<<"\n If the final sum is 100 cents (1 dollar), you win. Else you lose!! \n\n All set to play the game?? Press enter when you are ready!\n\n";

getch();

while(sum<100)

{

temp=rand() %100;

if(temp<=30)

{

Coin nickelObj(5);

}

else if(temp<=65)

{

Coin dimeObj(10);

}

else

{

Coin quarterObj(25);

}

}

cout<<"\n\n Total value added to the Sum = "<<sum<<" cents";

if(sum==100)

cout<<"\n\n *** You win ***";

else cout<<"\n\n *** You lose ***";

getch();

return 0;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Correct program:

#include <iostream>

#include <cstdlib>

#include <ctime>

#include <conio.h>

using namespace std;

int sum=0;

class Coin

{

int sideUp;

public:

Coin(int value)

{

toss(value);

}

void toss(int value);

};

void Coin::toss(int value)

{

if(rand() %100<=50)

{

sum+=value;

cout<<"\n You got a head. Value "<<value<<" added!!";

}

else

{

cout<<"\n You got a tail. No value added";

}

}

int main()

{

int temp;

cout<<"\n Quarter = 25 cents\n Dime = 10 cents \n Nickel = 5 cents\n\n";

cout<<"\n If the final sum is 100 cents (1 dollar), you win. Else you lose!! \n\n All set to play the game?? Press enter when you are ready!\n\n";

getch();

while(sum<100)

{

temp=rand() %100;

if(temp<=30)

{

Coin nickelObj(5);

}

else if(temp<=65)

{

Coin dimeObj(10);

}

else

{

Coin quarterObj(25);

}

}

cout<<"\n\n Total value added to the Sum = "<<sum<<" cents";

if(sum==100)

cout<<"\n\n *** You win ***";

else cout<<"\n\n *** You lose ***";

getch();

return 0;

}

Output;

You got a head. Value 10 added!! You got a head. Value 25 added! ! Total value added to the Sum115 cents You lose

Add a comment
Know the answer?
Add Answer to:
Getting this error. [Error] expected ';' after class definition #include <iostream> #include <cstdlib> #include <ctime> #include...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • import java.util.Scanner; public class Client{ public static void main(String args[]){    Coin quarter = new Coin(25);...

    import java.util.Scanner; public class Client{ public static void main(String args[]){    Coin quarter = new Coin(25); Coin dime = new Coin(10); Coin nickel = new Coin(5);    Scanner keyboard = new Scanner(System.in);    int i = 0; int total = 0;    while(true){    i++; System.out.println("Round " + i + ": "); quarter.toss(); System.out.println("Quarter is " + quarter.getSideUp()); if(quarter.getSideUp() == "HEADS") total = total + quarter.getValue();    dime.toss(); System.out.println("Dime is " + dime.getSideUp()); if(dime.getSideUp() == "HEADS") total = total +...

  • This is for C++ #include <random> #include <iostream> #include <ctime> using namespace std; /* In the...

    This is for C++ #include <random> #include <iostream> #include <ctime> using namespace std; /* In the game of craps, a shooter rolls 2 dice and adds the dots on the upper most faces of the dice. 7 or 11 on the first roll wins, 2, 3, or 12 on the first roll loses, andthing else is call the point and the player rolls again The following program fragment uses 1-way if statements simulate the 1st roll of the dice. Replace...

  • Find and fix errors #include <iostream> #include <cstdlib> #include <ctime> using namespace std; const int MIN...

    Find and fix errors #include <iostream> #include <cstdlib> #include <ctime> using namespace std; const int MIN = 1; const int MAX = 10; int getRandom(int low, int high); int main() {    int random_num = 0; int player_num; int tries; int seed = static_cast<int>(time(0)); bool guessed = false;    srand(seed); // call the getRandom function below       tries = 4; while ( tries > 0 && !guessed ) { cout << "Enter a number within the range 1 to...

  • Rewrite this code in Java please #include <iostream> #include <fstream> #include <cstdlib> #include <ctime> using namespace...

    Rewrite this code in Java please #include <iostream> #include <fstream> #include <cstdlib> #include <ctime> using namespace std; long length = 1000; const long max_length = 100000; int list[max_length]; void read() {     ifstream fin("random.dat", ios::binary);     for (long i = 0; i < length; i++)     {         fin.read((char*)&list[i], sizeof(int));     }     fin.close(); } void bubbleSort() {     int temp;     for(long i = 0; i < length; i++)     {         for(long j = 0; j< length-i-1; j++)...

  • // P13_2.cpp - This program adds money of two different people #include<iostream> #include<cstdlib> using namespace std;...

    // P13_2.cpp - This program adds money of two different people #include<iostream> #include<cstdlib> using namespace std; class AltMoney {     public:         AltMoney();         AltMoney(int d, int c);         friend void add(AltMoney m1, AltMoney m2, AltMoney& sum);         void display_money( );     private:         int dollars;         int cents; }; void read_money(int& d, int& c); int main( ) {      int d, c;      AltMoney m1, m2, sum;      sum = AltMoney(0,0);      read_money(d, c);      m1 = AltMoney(d,c);      cout...

  • Game of Craps C++ #include <iostream> using namespace std; void roll (int *); // using pointer...

    Game of Craps C++ #include <iostream> using namespace std; void roll (int *); // using pointer to catch the random variable value of two dicerolls at one time . //these global variable with static variable win use to operate the working of code . //static win, account because two times input given by user to add the diceroll with win number and //account (means balance of user) . static int account = 100; static int win = 0; int bet...

  • Am I getting this error because i declared 'n' as an int, and then asking it...

    Am I getting this error because i declared 'n' as an int, and then asking it to make it a double? This is the coude: #include "stdafx.h" #include <iostream> #include <fstream> #include <string> #include <algorithm> #include <vector> using namespace std; void sort(double grades[], int size); char calGrade(double); int main() {    int n;    double avg, sum = 0;;    string in_file, out_file;    cout << "Please enter the name of the input file: ";    cin >> in_file;   ...

  • implement coinclass and driver program within one source file, i.e. do not separate class specifications with...

    implement coinclass and driver program within one source file, i.e. do not separate class specifications with implementation Its a c++ problem 12. Coin Toss Simulator Write a class named Coin. The Coin class should have the following member variable: • A string named sideUp. The sideUp member variable will hold either "heads" or "tails" indicating the side of the coin that is facing up. The Coin class should have the following member functions: • A default constructor that randomly determines...

  • graph binary search for size and time c++ //System Libraries #include <iostream> #include <string> #include <cstdlib> #include <ctime> #include <iomanip> #include <alg...

    graph binary search for size and time c++ //System Libraries #include <iostream> #include <string> #include <cstdlib> #include <ctime> #include <iomanip> #include <algorithm> using namespace std; //User Libraries //Global Constants, no Global Variables are allowed //Math/Physics/Conversions/Higher Dimensions - i.e. PI, e, etc... //Function Prototypes //Execution Begins Here! int main(int argc, char** argv) { int n, i, arr[50], search, first, last, middle,count=0,count_in,tot; clock_t start, end; float duration; cout<<"Enter total number of elements :"; cin>>n; cout<<"Enter numbers"; for (i=0; i<n;i++) cin>>arr[i]; cout<<"Enter a...

  • Can someone explain me AddAtHead,AddAtTail And AddInOrder functions #include <iostream> #include <fstream> #include <ctime> #include <cstdlib>...

    Can someone explain me AddAtHead,AddAtTail And AddInOrder functions #include <iostream> #include <fstream> #include <ctime> #include <cstdlib> using namespace std; template <class T> class DNode{ public: T data; DNode *next,*prev; DNode(){ next=prev=NULL;} DNode(T d, DNode *n=NULL, DNode *p=NULL){ data=d; next=n; prev=p;} }; template <class T> ostream& operator<<(ostream &out, const DNode<T> &n){ out<<n.data<<' '; return out; } template <class T> class HCDLL{ DNode<T> *head; public: HCDLL(){ head=new DNode<T>; head->next=head->prev=head;} void addAtHead(T d){ head->next=head->next->prev=new DNode<T>(d, head->next, head); } void addAtTail(T d){ head->prev=head->prev->next=new DNode<T>(d,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT