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
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...
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...
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:...
I wrote the following java code with the eclipse ide, which is supposed to report the...
I wrote the following java code with the eclipse ide, which is supposed to report the number of guesses it took to guess the right number between one and five. Can some repost the corrected code where the variable "guess" is incremented such that the correct number of guesses is displayed? please test run the code, not just look at it in case there are other bugs that exist. import java.util.*; public class GuessingGame {    public static final int...
For some reason I followed the steps in my project and I am getting the incorrect...
For some reason I followed the steps in my project and I am getting the incorrect output and when I am submitting it, it gives me compilation error. Printing empty array -- next line should be blank Testing append: Shouldn't crash! Should print 100 through 110 below, with 110 on a new line: 100 101 102 103 104 105 106 107 108 109 110 Checking capacity of new array: OK Append test #2: Should print 100 through 120 below, on...
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...
my code has several functions; delete and backward functions are not working, rewrite the code for...
my code has several functions; delete and backward functions are not working, rewrite the code for both functions and check them in the main: #include<iostream> #include<cassert> using namespace std; struct nodeType {    int info;    nodeType *link; }; class linkedList { public:    void initializeList();    bool isEmptyList();    void print();    int length();    void destroyList();    void insertFirst(int newItem);    void insertLast(int newItem);    int front();    linkedList();    void copyList(const linkedList otherList);    void insertNewValue(int value);...