PDA

Click to See Complete Forum and Search --> : Easy Question


Lee M.
Feb 12th, 2001, 04:55 PM
I have a project due today for school, and it runs ok but repeats the question 2x, what am I doing wrong????



#include <iostream.h>
#include <ctype.h>
#include <string.h>

void main()
{

//Declare and initialize variables
float meShip = (float) 25.00; //Accumulator for ME
float txShip = (float) 30.00; //Accumulator for TX
float njShip = (float) 32.50; //Accumulator for NJ
short meCount = 0; //Counter for ME
short txCount = 0; //Counter for TX
short njCount = 0; //Counter for NJ
short errCt = 0; //Error Count
char state[3] = "";


while (state != "XX")
{
//enter input
cout << "Enter State where items are to be shipped (ME, TX or MJ) or press XX to end: " <<endl;

cin.getline(state, 3);
state[3] = toupper(state[3]); //Change to upper case

if (stricmp(state,"ME") == 0)
{ meCount = (meCount +1); }


else if (stricmp(state, "TX") == 0)
{ txCount = (txCount +1); }


else if (stricmp(state, "NJ") == 0)
{ njCount = (njCount +1);}


else if (stricmp(state, "xx") == 0)
{ cout << "Number of Entries in ME: " << meCount<< " Total Amount: $" << float(meCount * meShip) << endl;

cout << "Number of Entries in TX: " << txCount << " Total Amount: $" << float(txCount * txShip) << endl;

cout << "Number of Entries in NJ: " << njCount << " Total Amount: $" << float(njCount * njShip) << endl;

cout << "Number of Invalid entries: " << errCt << endl; }


else
errCt = (errCt +1);


}//End While


} //End of main

Please help!
Thanks!
Lee

HarryW
Feb 12th, 2001, 04:59 PM
while (state != "XX")

you can't check string equality like that unless you use the string class.

Lee M.
Feb 12th, 2001, 05:16 PM
uhhm, I thought I did...
#include <string.h>

Or am I incorrect? I am just learning

parksie
Feb 12th, 2001, 05:20 PM
Nope. Doesn't work like that :(.

The string class is in a header called string:

#include <iostream>
#include <string>

using namespace std; // Very important!

void main() {
string x = "This is my string";
string y = " again!";

string z = x + y;

z += "55";

cout << z << endl;
}

Lee M.
Feb 12th, 2001, 05:27 PM
I am not adding them, I am only checking to see if those letters were entered by the user, if so how many times were they entered

Lee M.
Feb 12th, 2001, 09:45 PM
Mahalo to you!
(Thanks Dude)