Hey,
so i spent all yesterday working on a ratio calculator for purchasing items. the program takes a given budget limit, takes a number of inputs (1-10) representing the value of an item being purchased, and tells you what same number of each item can be purchased for the given budget limit-
ie, you have 200k, you want to buy 3 items.
item x costs 89
item y costs 528
item z costs 111
the program calculates that you can purchase 274 of each item for a total expenditure of 200k.
the program works like it should and im just polishing it now.
problem is when the program requests the value of an item, if the user enters letters instead of numbers, the program dies instantly because that/those letters are being entered into an int variable.
is there any way to check if an input is numeric, or prevent users from entering non numeric inputs?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
int infograb()
{
for (int a = 0; a != Numberofratiovariables; a = a + 1)
{
cout << "please enter the name of item " << a + 1 << "." << endl;
cin >> itemname[a];
cout << endl << endl << "please enter the value of " << itemname[a] << "." << endl;
cin >> value[a]; //here is where we're grabbing the item value. the variable value[a] is int type
system("CLS");
}
system("CLS"); //looking back on this section of code, im thinking this cls is redundant
return 0;
}
|
also, not related to the original question, but is there a forum here where i can dump my program code, or upload the compiled program for more experienced coders to look at, critique, and suggest ways that i might improve?