something missing in my "Two Stones" problem

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!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
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>


using namespace 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;
}
1. Create integer representing the number of possible stones 1000000 : N

That you have, on line 26.
2. input the value the of N, (1 <= N <= 1000000)

Where is your input?
(You probably need a loop: "ask input repeatedly, until the value is acceptable.)
3. Create if else statement to determine winner (If there are an odd number of stones Alice wins
even number of stones Bob wins.)

It seems that the rest of problem description is meaningless fluff.
4. Create an output to tell who wins

Should the output be after step 3 rather than within?
Where is your input?

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 << //...


Hope this helps
Last edited on
Topic archived. No new replies allowed.