Hey, I am heading into my 3rd week of CS1 so i may be missing something simple. However i've created a program for the twostones problem on kattis that i feel like should work. I'm thinking maybe I am missing a function to optimize stone selection? anyways if anyone can see the problem and explain why it's producing the wrong answer i would greatly appreciate it!
/*
Take Two Stones
Kattis Practice
By: Andrew Libberton
9/7/2018
This program is designed to determine who would win in a game of stones where Alice and Bob choose a 2 consecutive stones two at a time
taking turns until there are no consecutive stones left. Both players play optimally. If there are an odd number of stones Alice wins
even number of stones Bob wins. Alice goes first and there are 1000000
1. Create integer representing the number of possible stones 1000000 : N
2. input the value the of N, (1 <= N <= 1000000)
3. Create if else statement to determine winner
4. Create an output to tell who wins
*/
#include <iostream>
#include <cmath>
#include <string>
#include <stdbool.h>
usingnamespace std;
int main() {
int N;
N = 0;
N = ( 1 <= N && N <= 10000000); //FIXME'<='; unsafe use of bool //fixed &&
//if (N % 2 == 0) //fixed removed ; // need alice to go first
if (N % 2 == 1 ) //FIXME Alice still doesn't go first
cout << "Alice Wins!" << endl; //Fixed changed cout << N << "Bob Wins!" << endl;
else //(N % 2 == 1); //didn't fix // illegal else without matching if c2181 //fixed if
cout << "Bob Wins!" << endl; //Fixed removed << N
cin.get();
return 0;
}
As mentioned by keskiverto you never get input from user you just set a variable
this is not getting input: N = 250;
this is getting input: cin >> N;
Input and output are done via the command prompt:
Input is the user typing something and pressing enter to give the information to the program cin >> //...
Output is the program displaying information on the command prompt cout << //...