Whats Wrong ?

hi, this short practice program wont work and i dont know why could you please help me.

#include <iostream> 
#include <cstdlib>
#include <cstdio>
using namespace std;

double square (double doublevar)
{
       return doublevar * doublevar;
       }
       
void displayexplanation(void)
{             
    cout << "this program sums the square of a multiple \n"
    <<  "series of numbers. terminate each sequence\n"
    << "by entering a negative number. \n"
    << "erminate each sequence by entering a empty\n"
    << "sequence.\n"
    << endl;
    return;
                   
                   }
double sumsquaresequence(void)
{         
    // loop forever 
    double accumlator = 0.0;
    for (;;)
    {
        // fetch another number 
        double dvalue = 0;
        cout << "Enter next value:   ";
        cin >> dvalue;
        
        // if its negative 
        if (dvalue < 0){ break; }
        
        // ...otherwise calculate the square 
        double value = square (dvalue);
        
        // now add accumulated values
        
    accumlator +=value;
}
// return acc 
return accumlator; 
           }
           
           
int main ()
{              
    displayexplanation();
    
    // continue to accumulate numbers
    for (;;)
    { 
       
        cout << "Enter next sequence: ";
         accumulatedvalue = sumsequence();
        
        if (accumulatedvalue <= 0 ){
                             break;}
        cout
  
 "\nThe total of the value squared is " << accumulatedvalue
             << "\n" << endl;}
             
             cout << "Thank you" << endl;
             system("pause"; return 0; }

accumulatedvalue was never declared.
A << is missing between cout and "\nThe total of th...


system("pause"; return 0; }
This is nonsensical. I suspect you meant
1
2
system("pause");
return 0; }

which might work but is still pretty bad.

Use of system is frowned upon because it asks the shell you are executing in to run some other programme for you. You have no guarantee that the other programme exists, and no guarantee that it does what you want. If someone replaces the pause command, and puts in something with the same name that wipes the hard-drive, you'd never know until you ran the programme.



Last edited on
@Above NO

getch(); return 0; }

Or to fix that error do

system("pause"); return 0; }
Last edited on
cheers, for correcting my sloppy work :0. i should take my time writing it. and i know system("pause"); is bad but i use it because it's easy and i have learnt like that. but i mean it cant be that bad considering i learn from a published book soooooooooo! but thanks anyway. i will try to use getch();
it cant be that bad considering i learn from a published book


Depends on the book. At risk of starting another book-war, if it's by Schildt stop reading it and if it advised you to use system("pause"); be wary of it :)

i will try to use getch();


getch is non-standard and is not present on many systems.
Last edited on
So then use cin.get();
could you please explain getch(); or cin.get();

i do not know how to use then
Topic archived. No new replies allowed.