Need help with "int" and "char" function

Warning for wall of text!
You have been warned!

Since I'm a beginners beginner, im going to be posting the entire code here.
Been struggling with this simple code for like 5 hours. Been having ALOT of problems with just about everything but now finally the only problem left is that I can't seem to find a function for my "navigator" program to realise that the user is typing two variables (like 10 or 15) without using int.
As soon as I use char, c++ complains about it and says I can't use =>, <=.. ye nothing but strict "=".
Any function that allows me to use those signs and that can remember more than 1 input from the user? (Also reason i don't want to use "int" is because if the user types a letter, then the entire thing crashes :(

(This is a school project so the level of knowledge from my part is very limited. Also i'm new to this site so I hope it's a kind community :) )

Thanks in advance!

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
using namespace std;

void Navigator() // skapar en funktion för skojs skull.
{
	cout << "\nHur l\x86ngt ska du \x86ka?" << endl; // Fråga efter distans.
	cout << "Ange distansen i km." << endl << endl;

	int dist;
	cin >> dist;

	if (dist >= 1) // <--- problem!
	{
		if (dist < 3)
		{
			cout << "\nDet \x84r g\x86ngavst\x86nd\n" << endl;
		}
		else if (dist > 7) // <--- problem!
		{
			cout << "\nTa bussen eller bilen.\n" << endl;
		}
		else if (dist >= 3|| dist <= 7) // <--- problem!
		{
			cout << "\nTa cyckeln.\n" << endl;
		}
	}
	else // Buggar då man trycker annat än siffran 0.
	{
		cout << "Knapptryckningen uppfattades inte" << endl; // bugg bugg bugg :(
	}
}

int main()
{
	while (true)
	{
		Navigator(); // anropar min skapade funktion.
		cout << "\nVill du forts\x84tta? j/n" << endl << endl;
		char kvar;
		cin >> kvar;
		if (kvar == 'N'|| kvar == 'n')
		{
			return 0;
		}
		else if (kvar == 'J'|| kvar == 'j')
		{
			cout << "\nD\x86 forts\x84tter vi!" << endl << endl;
		}
		else // om inget giltigt svar så
		{
			while (kvar != 'J'|| kvar != 'j'|| kvar != 'N'|| kvar != 'n')
			{
				cout << "\nKnapptryckningen uppfattades inte.\nVill du forts\x84tta? j/n" << endl << endl;
				cin >> kvar;
				if (kvar == 'J'|| kvar == 'j')
				{
					break;
				}
				else if (kvar == 'N'|| kvar == 'n')
				{
					return 0;
				}
			}
		}
	}
cin.get();
}
Last edited on
Topic archived. No new replies allowed.