Re: New to c++.net (need help)

From: Mike Wahler (mkwahler_at_mkwahler.net)
Date: 10/09/04

  • Next message: Faheem Mitha: "Re: integer type conversion problem/question"
    Date: Sat, 09 Oct 2004 17:12:50 GMT
    
    

    "Kathyoneal143" <kathyoneal143@aol.com> wrote in message
    news:20041009005350.19078.00002351@mb-m29.aol.com...
    > Ok, here is the program. When I put the while statement in there with the
    > (again == 'y' || again =='Y')
    > cout<<.....
    > I run it and it keeps asking me the same question... "Do you want to run
    the
    > program again" If I type "y" then it keeps asking me the same question but
    if I
    > type in a number to calculate then it will finish the program again.. Im
    sure
    > this is something simple and I'm just tired (begining program headaches)
    >
    > below is the program
    >
    >
    >
    > #include <iostream>
    > #include <iomanip>
    > using namespace std;
    >
    > int main()
    > {
    > int numOfEntries,count=1;//Variables for the amount of numbers to enter
    and the
    > counter
    > float total = 0.0;// this is the variable for the total
    > char again;// To loop the program
    >
    > cout <<"This program will calculate a sum of numbers\n";
    > cout <<"Please enter how many numbers you want to calculate\n";
    > cout <<"The number must be higher than Zero\n";
    > cin>>numOfEntries;
    > cout <<"\nItem Number\t\tAmount\n";
    > cout <<"--------------------------------------\n";
    >
    > if (numOfEntries <1)
    > cout <<"ERROR! You must enter a number greater than zero\n";
    >
    > while (count <= numOfEntries)
    > {
    >
    > float amountentered;
    > cout <<"Amount # " <<count <<"\t\t:";
    > cin >>amountentered;
    > total +=amountentered;
    > count++;
    > }
    > cout <<fixed<<setw(10)<<setprecision(2);
    > cout <<"--------------------------------------\n";
    > cout<< "The Total Amount is:\t " <<total <<endl;
    > cout<<""<<endl;
    >
    >
    > do
    > {
    >
    > cout << "Would you like to enter more numbers to calculate? (y/n)";
    > cin >> again;
    >
    > } while (again == 'Y' || again == 'y');
    >
    > cout <<"Please enter how many numbers you want to calculate\n";
    > cout <<"The number must be higher than Zero\n";
    > cin>>again;
    >
    > return 0;
    > }

    Carefully consider the short example I supplied. It indicates
    the solution to your problem (but doesn't supply it directly).
    Also be sure to look at Bart's reply. Here's a hint for when
    your program is behaving other than how you expect, especially
    when it involves decision points: Scatter output statements
    at stragegic points through your code which simply indicate
    that program flow has reached a certain point (this is common
    practice especially when one doesn't have or is unable to use
    a debugger).

    cout << "about to test x\n";

    cout << "x == " << x << '\n';
    if(x > 42)
    {
        cout "condition is true\n";
        /* your code */
    }
    else
    {
        cout "condition is false\n";
        /* your code */
    }

    cout << "after testing x\n";
    /* your code */

    etc. etc.

    Once you've fixed the problems, then go back and remove
    or comment out the diagnostic 'cout' statements.

    HTH,
    -Mike


  • Next message: Faheem Mitha: "Re: integer type conversion problem/question"

    Relevant Pages

    • Re: input and output questions about file
      ... using namespace std; ... junk.c:5: warning: type defaults to `int' in declaration of `std' ... junk.c:10: `string' undeclared ... junk.c:12: parse error before '/' token ...
      (comp.lang.c)
    • Re: Comparing files (Fast)
      ... I didn't knew what is was, but using fseek solved the problem. ... I'm using a timer utility Scott Meyers wrote for use ... > using namespace std; ... > int ch1,ch2; ...
      (comp.lang.cpp)
    • Re: return memory to the OS
      ... > 4 using namespace std; ... > 5 int main ... > possible to make STL return this memory to the OS (say using a system ... :: "out of confusion comes chaos -- out of chaos comes confusion and fear ...
      (comp.lang.cpp)
    • Re: Huge Floating Point Error
      ... using namespace std; ... int main ... floating point math is different from integer math. ...
      (microsoft.public.dotnet.languages.vc)
    • Re: Deadlocks on Update
      ... hint if you are not updating the table. ... WITHhint. ... > avalId int 4 No ... CleanCnt:1 Mode: U Flags: 0x0 ...
      (microsoft.public.sqlserver.programming)