My Program Skips certain bits of code (ifs mainly)

SO i am back again and sorry to be a bother but i don't even know what i would search this as and from my searching i've found nothing except to make it pause for press any key to enter or to exit the program that console does by default
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

#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <cstdlib> 
using namespace std;

int Armor, Health, result, status, goorno;
char choice, namespace1, namespace2, namespace3, yes, name[40], b, y;
int main()
{
	system("title Quick Attack Game");
	system("color 4");
	cout << "Welcome to The Game!\n";
	cout << "Please enter your name\n";
	cin >> name;
	cout << "Welcome " << name << " To the quick attack game!\n\n";
	cout << "Ready to begin?\n";
	cin >> choice;
	cout << "Ok, Let's Begin!\n";
	cout << " Your Begining Health is 110 and Armor 25, your current H (Health) and A (Armor) Will displayed after each turn\n\n";
	cout << "You will start with 3 Health potions if your health is under 50% it will double your current health if it is above it, 25 health will be added\n\n";
	cout << "You will get 3 armor repairs each repair will add 25 to your armor\n";
	cout << "Your Repairs and Health Potion will also be displayed at the end of each turn\n\n";
	cout << "Type y to continue!\n\n";
	cin >> b;
	cin.get(b);
	if (b = y)
		system("color 3");
	cout << "Round One Beginning!\n Best of Luck\n\n ";
	system("color 7");




}

Instead of it waiting for you to type Y it just says it and goes straight to roud one beginning and press any key to continue
You have to use "==" to compare two values, and you need a set of single quotes (' ') when referring to a single character. Also use curly braces ( { } ) around your statements inside the conditional.

Your conditional would look like

1
2
3
if (b == 'y') {
     system("color 3");
}
Last edited on

You have to use "==" to compare two values, and you need a set of single quotes (' ') when referring to a single character. Also use curly braces ( { } ) around your statements inside the conditional.

Your conditional would look like

1
2
3
if (b == 'y') {
system("color 3");
}

When i try this it still just ends it says type y to continue and then says press any key to continue in the console instad of asking for the input and waiting to see if it is or no
1
2
3
4
5
6
7
8
9
	cout << "Type y to continue!\n\n";
	cin >> b;
	if (b == 'y'){
		system("cls");
	system("color 3");
	cout << "Round One Begining!\n Best of Luck\n\n ";
	system("color 7");
}
}
Last edited on
[img]https://i.gyazo.com/c19c49f5043942addc0fcd4733f487d7.png[/img] That shows up instead of it waiting for me to type Y and it saying the round begins and such
SakurasouBusters wrote:
Should be :
cin.clear(); cin.ignore(1000, '\n'); cin >> b;

What's special about 1000?
Last edited on
Topic archived. No new replies allowed.