i am writing a program whereby i have written the instructions the shell of the program, and have written code for inputting values, but how do i collect all the information i have inputted. I am aware it involves arrays but can you help and point me in the right direction ?
Here is part of my program:
#include <iostream.h>
#include <string>
#include <conio.h>
main()
{
int salescode, bikeprice, modelcode, quantity;
string date;
char answer; //either yes or no
do
//the instructions to enter the i.d. code will be repeated (do...while
//loop) as long as the salescode is less than 1 or greater than 20.
{
cout << "\n\nPlease enter your identifiction code ";
cin >> salescode;
//the condition is tested
if (salescode < 1 || salescode > 20)
{
cout << ("\nTHIS I.D. CODE IS NOT VALID. TRY AGAIN \n");
}
}
//the instructions to enter the i.d. code will be repeated (do...while
//loop) as long as the salescode is less than 1 or greater than 20.
while (1 > salescode || salescode > 20);
//another do...while loop
do
{
cout << "\nPlease enter the bike price (one unit = 1 Euro) ";
cin >> bikeprice;
if (bikeprice < 1 || bikeprice > 500)
{
cout << ("\nINVALID PRICE. Bike prices cannot be 0 or more than 500. TRY AGAIN \n");
}
}
while (bikeprice < 1 || bikeprice > 500);
//another do...while loop
do
{
cout << "\nPlease enter the 3 digit model code ";
cin >> modelcode;
if (modelcode < 0 || modelcode > 999)
{
cout << ("\nINVALID MODEL CODE. TRY AGAIN \n");
}
}
while (modelcode < 0 || modelcode > 999);
//another do...while loop
do
{
cout << ("\nPlease enter the quantity sold ");
cin >> quantity;
if (quantity < 1 || quantity > 10)
{
cout << ("\nINVALID QUANTITY. TRY A NUMBER FROM 1-10 \n");
}
}
while (quantity < 1 || quantity > 10);
do {
cout << "\nPlease enter the date in this format dd/mm/yyyy: ";
cin >> date;
cout << "\nIs this the correct date ?\t" << date << "\tpress y/n: \n\n";
cin >> answer; //gets answer from user
switch (answer) {
case 'y':
cout << "\n\n\nThank You!\n\n";
break;
}
}while (answer != 'y');
}
So if you run my program as it is, how do i store the values entered for each of the commands prompted ?
I will need these values to be used later on to calculate the weekly sales.
Any ideas please ?
oh yeah, if i type in any other non integer, the program crashes.
what would you suggest.
I am new to c++ and programming
Thanks