Checking amount Function

Hello to all.
I am having some trouble writing code for a program that lets users input certain amounts for certain names and the program should then display it. The program should check the values to see whether or not it is higher than 200. If it is higher then 200 then it should output a Y. This is what i have so far. The code does not output the Y when a value is above 200. The "Y" should appear under the appropriate slot. Any tips?
Last edited on
Shouldn't you call maxEarning() after the input ?
Shouldn't you call maxEarning() after the input ?


I have now called it after the input but the situation is the same. :/

I did place the " high = maxEarning() ;" before input. I also tried it after but logically I believe it should be defined before input.

I called the function after its input
Last edited on
Your understanding of functions and variables needs some revision. L38-47 refer to the same high variable. maxEarning() is defined as returning a type string, but doesn't return anything. L13 high is defined as an array - but is not used as an array??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>

constexpr size_t arraySize{ 10 };

int main() {
	const std::string names[arraySize]{ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" };
	int amount[arraySize]{};

	for (size_t i = 0; i < arraySize; ++i) {
		std::cout << "Enter amount for " << names[i] << ": ";
		std::cin >> amount[i];
	}

	std::cout << "Name" << "\t" << "Amount" << "\t" << "ATH\n";

	for (size_t i = 0; i < arraySize; ++i)
		std::cout << names[i] << "\t" << amount[i] << "\t" << (amount[i] > 200 ? "Y" : "N") << '\n';
}

Topic archived. No new replies allowed.