Question

I don't know why this code wont build. I am using xcode and it has to...

I don't know why this code wont build. I am using xcode and it has to be in C++ //

// NickSchmidtProj3>cpp

// NickSchmidtProj3.Cpp //

// Created by Nick Schmidt on 9/18/19.

// Copyright © 2019 Nick Schmidt. All rights reserved.

//

#include <iostream>

using namespace std;

int ()

{

//declare variables of integer type and set the tooth_pick_left is 23

int user_pick, computer_pick;

int tooth_pick_left;

//int user_tooth_pick

cout << "let's play a game of "23"! \n";

//using do while loop to prompt until the user_pick is less than 4 do

{

//using another do while loop, compute untill tooth_pick_left isless than 0

do

{

//prompt player to play

cout << "It is your turn! pick your stick(s).";

cin >> user_pick;

if (user_pick < 1 || user_pick >3)

cout << "Error! You can pick 1, 2, or 3 sticks only! \n";

}while (user_pick > 1 || user_pick < 4);

//compute total_pick_left

tooth_pick_left = tooth_pick_left - user_pick;

//check the condition for computer_draw

//tooth_pick_left greater than 4 then pick 4-x

if (tooth_pick_left > 4)

{

computer_pick = 4 - user_pick;

}

//check the condition for sticks left between 2 and 4

else if (tooth_pick_left >= 2 && tooth_pick_left <= 4)

{

if (tooth_pick_left == 2)

computer_pick = tooth_pick_left - 1;

if (tooth_pick_left == 3)

computer_pick = tooth_pick_left - 2;

if (tooth_pick_left == 4)

computer_pick = tooth_pick_left - 3; }

//if computer draw is 1 then computer loses

else if (tooth_pick_left == 1)

{

computer_pick = 1;

cout << "Congratulations!! You Won The Game!!\n"; }

else

{

cout << "The Computer won the game... Sorry, Better luck next tim!\n'" break;

}

//display computer turn

cout << "Computers Turn:" << computer_pick

tooth_pick_left = tooth_pick_left - computer_pick;

//display the left toothpick

cout << " Tooth picks left: " << tooth_pick_left ;

}

while (tooth_pick_left > 0)

return 0;

}

Homework Answers

Answer #1

Answer:

Errors have been pointed out using comments

#include <iostream>

using namespace std;

int main() // this will int main() instead of just int()
{

    //declare variables of integer type and set the tooth_pick_left is 23

    int user_pick, computer_pick;

    int tooth_pick_left=23;

    //int user_tooth_pick

    cout << "let's play a game of '23'! \n";

    //using do while loop to prompt until the user_pick is less than 4
    do

    {

    //using another do while loop, compute until tooth_pick_left is less than 0


        do
        {
            //prompt player to play

            cout << "\nIt is your turn! pick your stick(s): ";

            cin >> user_pick;

            if (user_pick < 1 || user_pick >3)

                cout << "Error! You can pick 1, 2, or 3 sticks only! \n";
            else                                    //give a break statement in the else condition otherwise the program will only keep
                break;                             //asking for your input

        }
        while (user_pick > 0 || user_pick < 4); /*user_pick must be > 0 and not > 1 because if you do the latter then even if you

input 1 it will again ask you for input */

        //compute total_pick_left

        tooth_pick_left = tooth_pick_left - user_pick;

        //check the condition for computer_draw

        //tooth_pick_left greater than 4 then pick 4-x

        if (tooth_pick_left > 4)

        {

            computer_pick = 4 - user_pick;

        }

        //check the condition for sticks left between 2 and 4

        else if (tooth_pick_left >= 2 && tooth_pick_left <= 4)

        {

            if (tooth_pick_left == 2)

                computer_pick = tooth_pick_left - 1;

            if (tooth_pick_left == 3)

                computer_pick = tooth_pick_left - 2;

            if (tooth_pick_left == 4)

                computer_pick = tooth_pick_left - 3;
        }

        //if computer draw is 1 then computer loses

        else if (tooth_pick_left == 1)

        {

            computer_pick = 1;

            cout << "\nCongratulations!! You Won The Game!!\n";
        }

        else

        {

            cout << "\nThe Computer won the game... Sorry, Better luck next time!\n";
            break;

        }

        //display computer turn

        cout << "\nComputers Turn: " << computer_pick; //you forgot the semicolon here

        tooth_pick_left = tooth_pick_left - computer_pick;

        //display the left toothpick

        cout << " \nTooth picks left: " << tooth_pick_left ;

    }

    while (tooth_pick_left > 0);

    return 0;

}

Output:

Know the answer?
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
Similar Questions
Here are Dice Game which programed in C++ below. For this program, add a "cheater" function,...
Here are Dice Game which programed in C++ below. For this program, add a "cheater" function, which will prevent user from winning three times in the row (two times is OK, too). Also, add comments. #include #include using namespace std; int main() { int user,computer,sum,u_diff,c_diff,u_win=0,c_win=0; do { cout<<"User guess is(1 - 18) :"; cin>>user; if(user>=3&&user<=18) //the sum of three dice should be between 3 to 18 { cout<<"Computer guess is :"; computer=rand()%16+3; cout< cout<<"Sum of the three rolls is :";...
Hello, I feel like I am super close but I can not figure out why my...
Hello, I feel like I am super close but I can not figure out why my C++ code it not displaying the proper medium. Thank you! Here is an example of the output: Input : a[] = {1, 3, 4, 2, 6, 5, 8, 7} Output : Mean = 4.5 Median = 4.5 Code so far:   #include <iostream> using namespace std; int main() { int a[100]; int n,i,sum=0; float mean, medium; //read array size // read array cout<<"Enter array size:...
No matter what I do I cannot get this code to compile. I am using Visual...
No matter what I do I cannot get this code to compile. I am using Visual Studio 2015. Please help me because I must be doing something wrong. Here is the code just get it to compile please. Please provide a screenshot of the compiled code because I keep getting responses with just code and it still has errors when I copy it into VS 2015: #include <iostream> #include <conio.h> #include <stdio.h> #include <vector> using namespace std; class addressbook {...
USING C++ Topics: Friend functions Copy constructor ----------------------------------------------------------------------------------------------------------------------------------------- Lab 3.1 Create your objects in the stack...
USING C++ Topics: Friend functions Copy constructor ----------------------------------------------------------------------------------------------------------------------------------------- Lab 3.1 Create your objects in the stack (not on the heap). Add a friend function, kilotopound, which will convert kilograms to pounds. Change your weight mutator to ask whether weight is input in kilograms or pounds. If it is kilograms, call the friend function kilotopound to convert it to pounds and return pounds. There are 2.2 pounds in one kilogram. Create an object on the stack with the following information:     ...
Below is the problem that I have and here is the code that I have in...
Below is the problem that I have and here is the code that I have in c++. Can someone help me on what I am doing wrong or the correct code. A teacher has asked all her students to line up according to their first name. For example, in one class Amy will be at the front of the line, and Yolanda will be at the end. Write a program that prompts the user to enter the number of students...
Write a C++ program. Here is the project description. The game of "23" is a two-player...
Write a C++ program. Here is the project description. The game of "23" is a two-player game that begins with a pile of 23 toothpicks. Players take turns, withdrawing either 1, 2, or 3 toothpicks at a time. The player to withdraw the last toothpick loses the game. Write a human vs. computer program that plays "23". The human should always move first. When it is the computer's turn, it should play according to the following rules: 1. If there...
can someone edit my c++ code where it will output to a file. I am currently...
can someone edit my c++ code where it will output to a file. I am currently using xcode. #include <iostream> #include <cctype> #include <cstring> #include <fstream> using namespace std; bool inputNum(int [],int&,istream&); void multiply(int[],int,int[],int,int[],int&); void print(int[],int,int,int); int main() {ifstream input; int num1[35],num2[35],len1,len2,num3[60],len3=10,i; input.open("multiplyV2.txt"); //open file if(input.fail()) //is it ok? { cout<<"file did not open please check it\n"; system("pause"); return 1; }    while(inputNum(num1,len1,input)) {inputNum(num2,len2,input); multiply(num1,len1,num2,len2,num3,len3); print(num1,len1,len3,1); print(num2,len2,len3,2); for(i=0;i<len3;i++) cout<<"-"; cout<<endl; print(num3,len3,len3,1); //cout<<len1<<" "<<len2<<" "<<len3<<endl; cout<<endl;    } system("pause"); } void...
This is the code I have written for my Java homework assignment but I can't seem...
This is the code I have written for my Java homework assignment but I can't seem to get it to run. Any help would be appreciated! import javax.swing.JOptionPane; import java.io.*; import java.util.Scanner; public class javaGamev5 { public static void main(String[] args) throws IOException { String question = null, answerA = null, answerB = null, answerC = null ; int menuChoice = 0, correctAnswer = 0, points = 0, score = 0, highscore = 0; displayIntro(); do { menuChoice = displayMainMenu();...
In this code, I build a single-linked list using a node class that has been created....
In this code, I build a single-linked list using a node class that has been created. How could I change this code to take data of type T, rather than int. (PS: ignore the fact that IOHelper.getInt won't work for the type T... ie second half of main). Here's my code right now: public class SLList { public SLNode head = null; public SLNode tail = null; public void add(int a) {// add() method present for testing purposes SLNode newNode...
i want to complete this code to insert a new node in the middle of list...
i want to complete this code to insert a new node in the middle of list (take a node data from user, search the node and insert new node after this node). this is the code #include <iostream> #include <stdlib.h> using namespace std ; struct Node{                int data;                Node *link ;}; struct Node *head=NULL, *tail=NULL; /* pointers to Node*/ void InsertFront(); void InsertRear(); void DeleteFront(); void DeleteRear(); int main(){                int choice;                do{                               cout << "1:...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT