I need some help guys [Newbie]

Hey guys, I'm a newbie at C++ and I was wondering what is wrong with my code? I am trying to limit an integer in a struct to fit within a certain range (I know this code doesn't contain ranges as such, in the if statement) but I'm confused on what to do. I don't get an error when I compile the code I just get the number "12" as a cout in the console. What I'm looking for the program to do is utilise the if else statements instead of printing the bloody number! :(

It's probably something stupid :)
Thanks
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
#include <iostream>

	int main(){

		struct Strct_StudentRecords {
		char name[20];
		int identifier;
	};

	Strct_StudentRecords AdamPotato{
		"Adam Potato",
		12
	};

	if (AdamPotato.identifier == 20 || 30){
		std::cout << AdamPotato.identifier;
	}

	else {
		std::cin.clear();
		std::cout << "derp" << std::endl;
	}

	
	std::cin.get();
	return 0;

}


[Edit] I know the cin.get() thing is a bad idea but I'm using Visual Studio 2013 and I heard it was a way to get the damn thing to compile without exiting straight away :)
Last edited on
I'm not sure if it will fix the problem, but it should be
if (AdamPotato.identifier == 20 || AdamPotato.indentifier == 30)
1
2
3
if (AdamPotato.identifier == 20 || 30){
std::cout << AdamPotato.identifier;
}

Should be:
1
2
3
if (AdamPotato.identifier >= 20 && AdamPotato.identifier<=30){
std::cout << AdamPotato.identifier;
}


That will check for the range, 20 to 30 inclusive.

Aceix.
That was a pain in the ass! Thank Guys!!!:D It's working!
You're both awesome, really good community here

ThisGuyIsBrad, just so you know I got this error but Aceix your one is the solution (Just incase you wanted to know:) ) : 1>------ Build started: Project: C++ Learning, Configuration: Debug Win32 ------
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppBuild.targets(388,5): warning MSB8028: The intermediate directory (Debug\) contains files shared from another project (Project1.vcxproj). This can lead to incorrect clean and rebuild behavior.
1> Source.cpp
1>c:\users\windows 8\documents\visual studio 2013\projects\project1\project1\source.cpp(16): error C2039: 'indentifier' : is not a member of 'main::Strct_StudentRecords'
1> c:\users\windows 8\documents\visual studio 2013\projects\project1\project1\source.cpp(6) : see declaration of 'main::Strct_StudentRecords'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Topic archived. No new replies allowed.