My program is just flat out skipping a part?

So, in a C++ 2 class, pretty simple stuff compared to what all I've seen on these forums for how y'all write. Anyways, my issue has become urgent enough, and my instructor unresponsive enough that I must ask for help.

The purpose of this program is to input a roman numeral into a string type variable, then split it up to char and add up the numbers.

My issue is that at the end of the program, when displaying the variable, it appears to have remained 0. I have attempted to write this program over 10 different times, with each attempt looking more or less like this last one here.

I really hope after writing it this many times, it's not something really simple that I flat out missed, as easy as it would be to fix.

Anyways, here's my code, thank you for any help you can offer!


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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int main()
{
	string inputstring;
	char input[10];
	int total;

	total = 0;

	cout << "Enter the Roman Numeral, up to 10 char: ";

	cin >> inputstring;

	cout << "\n\n";

	for (int i = 0; i > 10; i++)
	{
		input[i] = 'a';
	}

	for (int i = 0; i > 10; i++)
	{
		input[i] = inputstring[i];
	}


	for (int i = 0; i > 10; i++)
	{
		if (input[i] == 'm' || input[i] == 'M')
			total += 1000;
		else if (input[i] == 'd' || input[i] == 'D')
			total += 500;
		else if (input[i] == 'c' || input[i] == 'C')
			total += 100;
		else if (input[i] == 'l' || input[i] == 'L')
			total += 50;
		else if (input[i] == 'x' || input[i] == 'X')
			total += 10;
		else if (input[i] == 'v' || input[i] == 'V')
			total += 5;
		else if (input[i] == 'i' || input[i] == 'I')
			total += 1;
		else
			total += 0;
	}
	/*
	for (int i = 0; i > 10; i++)
	{
		switch (input[i])
		{
		case 'm':
		case 'M':
			total += 1000;
			break;
		case 'd':
		case 'D':
			total += 500;
			break;
		case 'C':
		case 'c':
			total += 100;
			break;
		case 'L':
		case 'l':
			total += 50;
			break;
		case 'X':
		case 'x':
			total += 10;
			break;
		case 'V':
		case 'v':
			total += 5;
			break;
		case 'I':
		case 'i':
			total += 1;
			break;
		case 'a':
			total += 0;
			break;
		default:
			cout << "Numeral contains invalid value!\n";
			break;
		}
	}

	*/

	cout << "\n\nThe value is: " << total <<  "\n\n";
		
	system("pause");

	return 0;
}


Note that I usually use a lot more, well, functions, and less elementary coding than this (again, nothing like what some of ya'll be doing) but I wrote this as simple as I could to help eliminate the problem.

The code surrounded by notes was eliminated because it was having the same problem as I'm having already, so that's why that's like that lol.
1
2
3
4
	for (int i = 0; i > 10; i++)
	{
		input[i] = inputstring[i];
	}
This will not run even once, because i > 10 is false on first iteration. There is second snippet with same problem.
I was hoping my oversight of logic was the fix here, unfortunately now it triggers a breakpoint. I am not familiar with "breakpoints."
If you're running it in Visual Studio, it probably means that your program crashed.

Just to make sure, you changed the for (int i = 0; i > 10; i++) to for (int i = 0; i < 10; i++)?
Topic archived. No new replies allowed.