Hellooo I am a new beginner of C++.
I've found difficulties when doing the following simple programme.....
Please help!!
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
|
#include <cstdlib>
#include <string>
#include <iostream>
#include <cctype>
using namespace std;
int main(int argc, char *argv[])
{
string itemcode, itemdescription;
double itemweight, itemunitprice;
int quantityrequired;
char answer;
do {
cout << "Enter item code: ";
getline (cin,itemcode);
cout << "Enter item description: ";
getline (cin,itemdescription);
cout << "Enter item weight in grams: ";
cin >> itemweight;
cout << "Enter item unit price $: ";
cin >> itemunitprice;
cout << "Enter quantity required: ";
cin >> quantityrequired;
double totalweight = itemweight * quantityrequired;
double totalprice = itemunitprice * quantityrequired;
cout << "Summary Data for Item "<< itemcode << ","<< itemdescription << endl;
cout << "Total Weight: " << totalweight << " grams" << endl;
cout << "Total Price: $" << totalprice << endl;
cout << "Another?(Y/N): ";
cin >> answer;
if ((answer!='Y')&&(answer!='y'))
{
break;
}
} while(1);
system("PAUSE");
return EXIT_SUCCESS;
}
|
Problem 1>> When I ask for user confirmation (Y/N), how can I make "Y"="y" (i.e. ignore the lettercase)?? Since before I define answer='Y', if I enter 'y', it sees 'y', 'n' and 'N' as not equal "Y"....then the programme quits.. which is not what I want! I temporarily use (answer!='Y')&&(answer!='y') to present...but it looks stupid...
Problem 2>> If I enter 'Y', it loops again. However, on the screen, the prompt "Enter item code" and "Enter item description" combine into one line. That means when it starts looping, I am not allowed to enter item code and item description anymore...I can only enter the remainings....
Please HELP!!Thank you so much!!!!
It really kills time...I've been spending 3 days on tackling it...(tiring)!!!