~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hmm.. looks like you really new to programming.

"main()" as you say is the entry point for the program you write. Syntactically and technically you cant write anything outside main except macros, function definations and declarations, and global variables.

So if you want to write "cin" outside main create your own function and then write cin anywhere in that function you want.

By the way, what are you trying to achieve? IF you are a complete newcomer to prog then try out the sticky or thread "Starting C" which will help you out in getting some programming concpets cleared. Also look at these sites.

http://www.cprogramming.com/tutorial/lesson1.html
http://www.cplusplus.com/doc/tutorial/

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Maybe some changes incorporated would do the job...
Try to understand the changes made and learn something from the differences in what you had written prev and this code...

#include <iostream>
#include <cstring>
using namespace std;
const double PI = 3.14 ;
void getData(double& length, double& width, double& price);
void getData(double& diameter, double& price);
double computeUnitCost(double diameter, double price);
double computeUnitCost(double length, double width, double price);
int main()
{
        char pizzaType = '\0';
        bool okay = true;
        double price = 0.0 ;
        do {
        cout << "R => round pizza\tS => square pizza" << endl << endl1;
        cout << "Please enter in the type of pizza: " ;
        cin >> pizzaType;
        pizzaType = tolower( pizzaType ) ;
        cin.clear() ;
        cin.ignore(numeric_limits<streamsize>::max() , '\n');
        okay = (pizzaType == 'r' || pizzaType == 's');
        if( !okay )
            cout << "\nYou entered an invalid pizza type!" << endl;
        }
        while(!okay);
        if (pizzaType == 'r')
        {
        double diameter = 0 ;
        getData(diameter, price);
        cout << "The price per square inch for this pizza is " << computeUnitCost(diameter, price) << endl;
        }
        else
        {
        double length = 0, width = 0 ;
        getData(length, width, price);
        cout << "The price per square inch for this pizza is " << computeUnitCost(length, width, price) << endl;
        }
        cin.get( ) ;
        return 0 ;
}
void getData(double& length, double& width, double& price)
{
    cout << "Enter in the length of the pizza: " ;
    cin >> length;
    cout << "Enter in the width of the pizza: " ; …
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Using &quot;scanf&quot; to read character input is a recepie for disaster, however small the purpose maybe. Post your entire code and I will show you an alternative. PS: ALso declare your array as char sequence[ BUFSIZ ] = {\'0'};

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Dont talk in riddles, post the entire code and we will help you out.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

ios646.h is apparently available in the C99 C standards. But I don't know how many compilers have implement those new C standards yet.

I use Code::Blocks IDE which comes packed with the GCC Mingw compiler and the C File created in it does not recognize the C++ keywords.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Again, it depends on which country you live in. Not all keyboards have a & key!!!! Actually &quot;and&quot; looks a lot more readable than &quot;&&&quot;. Dev-C++ uses a much more international open source GNU compiler.

As expected from a Python proponent :D But seriously, i agree with Mr. Iamthwee, its would be better NOT to use such keywords which are fully integrated in C++ standards but require the inclusion of a seperate header file #include <iso646.h> . So if you want your C++ code to be compatible with C standards, better stick to the && operator.

C90 does not have these built-in keywords, but it does provide a standard header file that contains definitions for the same words as macros, behaving almost like built-in keywords. The recommended practice for code intended to be compiled as both C and C++ is to use &quot;and&quot; identifiers only for special meanings, and only after including the header <iso646.h> .

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

There's really no need to be horrid. :confused:

Heh, dont mind him, it was just a fatherly nudge..:D
After all he is the MOD you know

Anyways please post the code which you have written and we will help you out.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

How about something simple like:

for( int i = 0; i < roomNumber; ++i )
{
   // do what you want here
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Think about it logically, where do you need to keep the loop. It should be obvio after the variables required throughout the prog have been entered by the user. So the loop should logically be placed before the block when you start accepting theroom specs from the user. Hence place the loop after you ask the number of rooms and the tile size from the user.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It would really your problem if you could create different functions for different tasks like: 1. Accepting the data 2. Performing the conversions 3. Performing the calculations for the number of tiles. If classes have been introduced in your course you can try creating a class "Room" which will pack all the data and functions in a single abstraction. Incorporate the followign changes and repost. It will also help you get good grades if you perform the task using functions.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Looks like you have got your specification of stack wrong out there.
Please take a look HERE.

  • Also what exactly does D_size stand for ? You cant just change the size of an array once declared.
  • Also dont use "system("pause")" for pausing the program, its bad programmign practice. Use "cin.get()" instead.
  • Your push and pop operations dont take any parameters,so how would they know which stack to perform those operations on ?
  • Also write the helper functions like "is_empty( Stack a )" and "is_full( Stack b )" to perform easy runtime checking.

Incorporate those changes and then repost but do read the link i have posted.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Heh definately the beginning of a brave new world for me :D

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

SQL stands for Structured Query Language, it is more of a standard than a language. The Database packages which implement SQL are Oracle, MySQL, MS SQL Server 2005, etc. to name a few.

PHP is the server side scripting language used to impart dynamic behaviour to the web pages. And it would be a definate plus on your side if you knew the basics of SQL before attempting to tacke server side scripting languges like PHP since all the dynamic pages do is query the database in one form or the other.

It would be a different thing is you are learing PHP to develop standalone applications using the PHP GTK+. If that is the case then you dont need to know SQL.

http://www.w3schools.com/sql/default.asp
http://sqlcourse.com/intro.html

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Why not try to use an open source external library for your needs. It will provide all the kind of control you need over playing your sound. One eg. of it is Audiere.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Oh silly me and silly you !!!

Where is the "#" symbol before the "include <stdio.h>" part of header inclusion ???

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

sory im complete newbie

i have

include <stdio.h>

int main()
{
int x;
   for(x=1; x < 10; x++)
   {
   
printf("%d\n second ", a);
   }
return 0;
}
for.c:1: error: syntax error before ‘<’ token

Hmm you are declaring the variable "x" for controlling the for loop and printing the second values but usign an undefined variable "a" for printing the desired output ?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

PHP and other server side scripting languages was specifically designed for the purpose of doing away with the cumbursome work associated with the server side scripting using C and C++.

If you anyways usign PHP functions why do you want to use C++ ?
Why not design the site using just PHP which has a lot of support and tuts on the net related to creating the site from start to end.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

yes but how to enter sleep in this file

#include <stdio.h>
#include <windows.h>

int main()
{
int a;
int b;
    a = 3;
    b = 30;
    while (a < b)
    {
    printf("%d\n crap .....", a);
    a = a + 1;
    Sleep ( 2000 ) ;
    }
return 0;

}

But the thing is that the above code will work only on windows.

I havent as such personally worked on Linux but if you using Linux (like your avatar says i think) then try using the usleep (2000) function (notice the lowercase "s") here the parameter passsed is time in microseconds.

Also dont forget to include the #include <unistd.h> instead of the windows header.

#include <stdio.h>
#include <unistd.h>

int main()
{
int a;
int b;
    a = 3;
    b = 30;
    while (a < b)
    {
    printf("%d\n crap .....", a);
    a = a + 1;
    usleep ( 2000 ) ;
    }
return 0;

}

Hope it helped, by.e

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Please try to search the forum with the required keyword and then post if your query here.

Maybe you should look here for solution
http://www.daniweb.com/techtalkforums/thread56763.html

Just integrate the sleep funtion given there below the display stmt in the while loop and thigs will work out fine for you.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

yes that worked great
why
Code:
[10]

that makes no sense for me (newbie)

Because its the null terminator in the end which differentiates between normal character arrays and C Style Strings. Just remember to think of '\0' whenever you think of strings in C and life would be easier for you:idea:

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

ok one more question

why

[BUFSIZ] = {'\0'}

Initialization along with declaration.

This initializes all the elements of the char array which we are going to use as a C Style string to the null terminator which actually marks the end of C Style string. Safe and simple.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Please enclose your code in code tags before posting it, this is the second time i have edited your post to add code tags.

And as far as the code you posted is concerned, it doest work coz the dataype "char" is meant to store only a single character so whatever amount of text you try to put into it will store the first charcter only since it has the capacity of storing only one character.

This is the same as saying you cant store a real number in the integer datatype.

int result = 3 / 2;

Does result when printed out give you 1.5 ?
No because int only capable of handling integers without any fractional component in them.

If you are in need of the kind of functionality you require you can try out one of the many scripting languages out there. Interpreted, hassle free, lot of inbuilt functions, typelesss and ease of coding.

Some of my favourites:
1. Perl
2. Python
3. Lua

Hope it helped, bye.

[EDIT] Mr. Dragon beat me to it :D [/EDIT]

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You are getting one character as output since you using a container or a variable which can only store a single character (i.e. the char datatype)

Use a character array to take in user input and output it using

printf ("My string is %s " , my_char_array ) ;

Something like:

int main (void)
{
    char my_string [BUFSIZ] = {'\0'} ;
    printf ("Enter string: " ) ;
    fgets (my_string, BUFSIZ, stdin) ;
    printf ("\n%s", my_string ) ;

    return 0 ;
}

Hope it helped, bye.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I did not suggest he write to the same file that he's reading. read the sudo-code again please -- "write to new file"

Actually Mr. WaltP did not direct his comment to you.
If you will read the OP recent post:

if i want to write to a file, do i have to fread it first or just
fwrite it straight away ?

Mr. WaltP's comment I think is directed to the OP.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hmm looks like i did some typing mistake in my previous post. But just to make my point concrete here is a small snippet:

circle<T>::circle(T a,T b)
{
  x1 = a;
  y1 = b; // you can keep even "a" here depends on ur requirement
  x2 = a;
  y2 = b;
}

Just write this additional constructor and everything should work out fine for you. And if your problem is solved post again so that others can gain help from it and the MOD can mark it as solved.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Write a costructor which accepts 4 arguments along with the constructor which you have written which accpets 2 args.

Write something like

Circle (T a, T b, T c, T d) { ... }

Bye.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hmm it just requires few mods which u can esily do, but still if the below solution doesnt satisfy your requirement feel free to modify.

int main()
{
    string name = "here is the code" ;
    char* tmp_name = new char ( name.size() ) ;
    strcpy ( tmp_name,name.c_str() ) ;
    for (int i = 0; i < strlen (tmp_name); ++i )
    {
        cout << endl << "Character " << i + 1 << " is " << tmp_name [i] ;
    }
    return 0 ;
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
#include <iostream>
#include <cstdlib>
#include <cmath>
#define pi 3.14159265
using namespace std;
template <class T>
class circle {
  public:
    circle();
    circle(T,T,T,T);
    void populate_classobj(T a1, T b1, T a2, T b2);
    T radius();
    T circumference();
    T area();
  private:
    T x1,x2,y1,y2;
  protected:
    T distance();
}; //End of class
//Function definitions
template <class T>
circle<T>::circle(T a1,T b1,T a2,T b2)
{
  x1=a1;
  y1=b1;
  x2=a2;
  y2=b2;
}
template <class T>
circle<T>::circle()
{
  x1=0;
  x2=0;
  y1=0;
  y2=0;
}
template <class T>
void circle<T>::populate_classobj(T a1, T b1, T a2, T b2)
{
  x1=a1;
  y1=b1;
  x2=a2;
  y2=b2;
}
template <class T>
T circle<T>::radius()
{
  return distance();
}
template <class T>
T circle<T>::circumference()
{
  return pi*radius()*2;
}
template <class T>
T circle<T>::area()
{
  return pi*pow(radius(),2);
}
template <class T>
T circle<T>::distance()
{
  return sqrt( pow((x2-x1),2) + pow((y2-y1),2) );
}
 
int main()    //Main
{
  //Initialize variables
  float x1,x2,y1,y2;
  int input=0;

// specyin type is must

   circle<double> my_obj1 (1,3, 4, 5); 

// you didnt write a constructor which took 2 args but still were 
// constructing objs by passing in just 2 values 

   circle<double> my_obj2 (1.5,-0.5,-6.65,10.0);


  while(input<4)
  {
    //Choose functions to compute
    cout<<"Press 1 to compute the radius of the circle"<<endl;
    cout<<"Press 2 to compute the circumference"<<endl;
    cout<<"Press 3 to compute the area of the circle"<<endl;
    cout<<"Press 4 to enter new values for Object 1"<<endl;
    cout<<"Press 5 to enter new values for Object 2"<<endl;
    cout<<"Press 6 to exit"<<endl;
    cin>>input;
    //If statements
    if(input>6)
    {
      cout<<"PLEASE PICK A NUMBER BETWEEN 1 AND 6"<<endl;;
      input=0;
    }
    if(input==1)
    {
      cout<<"Radius of object 1 equals: …
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Try something like:

int main()
{
    string name = "here is the code" ;
    char* tmp_name = (char*) malloc ( name.size() ) ;
    strcpy ( tmp_name,name.c_str() ) ;
    for (int i = 0; i < strlen (tmp_name); ++i )
    {
        printf ( " \ncharacter %d is %c ", i + 1, tmp_name [i] ) ;
    }
    return 0 ;
}

It is pretty simple to undertand program, ofcourse there are many other ways out there to do the same thing. This was just one of them.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Before answering your question i for the last time request you to post the code in the way which i have posted, neat , clean, indented and make it stand out using code tags. Last and final warning otherwise you would lose the friend who is trying to help you out.

printf ("Enter weight #%d ", i+1);
// ask the user to input in the weight

fgets (buf, BUFSIZ, stdin);

// this is a function which accepts the input given by the user and puts
// it in a character array. The variable "buffer" is declared and defined
// an array of BUFSIZ or "512" characters (here BUFSIZ is a constant
// built inside the compiler )

// stdin : since i am accepting the input from standard input stream
// or device which is the keyboard in this case. You can check the
// prototype of this function at www.cppreference.com

if ( buf [strlen(buf) - 1] == '\n' )
buf [strlen(buf) - 1] = '\0' ;

// here in these two stmts i remove the stray newline character which
// also entered the char arrray along with the normal input since you
// pressed the RETURN or the ENTER key. so if the last element of the
// char array is the newline character, i replace it with a null terminator
// (c style strings are character arrays with the '\0' at …

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I didnt change the logic of the program but just made the syntax errors which bugged you to go away. I would very much recommend you to format your code properly otherwise i wont be much of a help in the near future coz its really difficult to make out the problem with the code formatted in a bad way.

Also in your code in place of "i" variable you have written the number "1" which caused your program to crash. If you are coding in Notepad i would very much recommend you to switch to a syntax highlighter and indenter IDE which would make your as well as our task easy.

int main(void)
{
    double x[4] = {1.2,2.4,3.6,4.8};
    double f[4] = {0.1,0.2,0.3,0.4};
    double xave = 0.0;
    double ftotal = 0.0;
    int i;
    double weights[4] = {0};
    char buf[BUFSIZ];
    for(i = 0; i < 4; ++i)
    {
        printf ("Enter weight #%d ", i+1);
        fgets (buf, BUFSIZ, stdin);
        if ( buf [strlen(buf) - 1] == '\n' )
            buf [strlen(buf) - 1] = '\0' ;
        weights[i] = atof(buf);
    }

    for (i=0; i <4; i++)
        ftotal += f[i];


    if  ( (int) ftotal != 1 )
    {
        printf("error\n");
        exit (1);
    }

    for(i=0; i<4;i++)
    {
        xave += f[i]*x[i] ;
        printf("\nThe weights are %f",f [i]);
    }
    printf("\nThe average is %f\n",xave);

}

Hope it helped, bye.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yeah even i respect Python really a lot coz of the top class games made using it (search www.gamespot.com for Severance:Blade of Darkness and Freedom Force) and also since its used in game scripting (stackless python for threading support).

Well I better stop going off the track least some Mod busts me :)
(if you have anything to ask or say just PM me)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You are most welcome Mr. Moderator :)
Hope you enjoyed your stay at the C++ forums

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hmm maybe you should carry out the processing in your snippet only when the vector is not empty.
It can be easily done using something like:

vector<int> v;

for( int i = 0; i < 5; i++ ) {
   v.push_back(i);
 }
 while( !v.empty() ) {
   cout << v.back() << endl;
   v.pop_back();
 }

Hope it helped, bye.

[edit]
Or maybe you can in a smart way check if the user decided to leave the vector empty and in that case you can just create a default floating point vector for illustrating your point. That way it wont make a difference if the user leaves out the inputting part since your point will be very well driven home with your default array and the teachings will reach the needy :mrgreen:
[/edit]

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Now that is sweet, except I wouldn't use exit (1), but would rather stay in the input loop.

Thanks for the appreciation.
Hmm i guess you are right, no use being too harsh :)
But that just involves adjusting the "if" stmt a bit and voila one would get what he wants.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I agree with you, cin.get() is the portable way to wait, but take a look at a small code snippet I wrote a long time ago:
http://www.daniweb.com/code/snippet105.html

I would love, if you could explain to me why cin.get() is such a flop in this fairly simple case.

Just thought would let you know that your program crashes when i dont enter any floating point input when asked for before entering "q" and pressing the RETURN key. (maybe you wanted to have it that way, i have no way of knowing, just my 2 cents).

I would love, if you could explain to me why cin.get() is such a flop in this fairly simple case.

This is because of the stray '\n' left in the input stream which occurs when the user presses the return key to convey his choice.

Just append the stmts:

cin.clear();
cin.ignore(std::numeric_limits<streamsize>::max(),'\n');

at the end of program before the cin.get () and everything should work out to be fine without that nasty "system" call which kills the so much loved portability.

Maybe you would want to take a look here:
http://www.augustcouncil.com/~tgibson/tutorial/iotips.html

Hope it helped, bye.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

OH sorry Mr. Vegaseat my bad, thanks for pointing out the flaw to me. The OP required the user to input floating point values so i actually shouldnt have taken a decimal input in the first place.

Well here is a near foolproof Implementation of the input accepting phase for your program which accpets only valid floats.

int main (void)
{
    int counter = 1 ;
    float  my_weight = 0;
    char buffer [BUFSIZ] = {'\0'} ;

    while (counter <= 4 )
    {
       printf ("Enter the weight %d: ", counter) ;
       fgets (buffer, BUFSIZ, stdin) ;

        if ( ! isdigit (buffer [0] ) )
        {
            printf ("Illegal input") ;
            exit (1) ;
        }

       if ( buffer [strlen (buffer) - 1] == '\n' )
         buffer [strlen (buffer) - 1] = '\0' ;

         my_weight = atof (buffer) ;

       if ( my_weight > 0 && my_weight < 10)
       {
          counter ++ ;
        }
       else
       {
          printf ("Incorrect choice!!!\n") ;
        }
    }
    return 0 ;
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

My post was not meant to contradict or show you wrong, just to point to the OP not to use the system functions when the same thing can be done using the std library functions.

This will be useful when he wants to write normal programs not involving "windows" specific code and needs the pause functinality.

Talking about heavy overhead, the iostream header creates about 95% of the overhead.

which cant be avoided when you are all set to write some concrete code snippets.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Better not call the "system" functions like system ("pause") .

Your job can be very well done using the function cin.get() which does the same function without invoking the system procedures which incur heavy overheads.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Hi,
What should i add on so that user can enter the four weights from the keyboard. The program should print an error message is the weights are out of range?

Try something like:

int counter = 1 ;
while (counter <= 4 )
{
   printf ("Enter the weight %d: ", counter) ;
   scanf ("%d", &my_weight [counter - 1] ) ;
   
   if ( some_condition_of_validity)
   {
      counter ++ ;
    }
   else
   {
      printf ("Incorrect choice!!!") ;
    }
}

This should keep on asking the user the choice until he enters a correct number.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yes if your OS is 32 bit windows OS and if it is 64 bit OS then just call it Win64 API :)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Try out something like:

#ifndef SAVINGSACCOUNT1_H
#define SAVINGSACCOUNT1_H

class SavingsAccount 
{
private:
    float annualInterestRate;
    float savingsBalance;
    
public:
    SavingsAccount()
    {
      annualInterestRate = 0;
      savingsBalance= 0;
    }
    
    SavingsAccount (float my_interest_rate, float my_savings_balance)
    {
        annualInterestRate = my_interest_rate ;
        savingsBalance = my_savings_balance ; 
    }
    
    float calculateMonthlyInterest()
    {
        float subtotal = 0;
        float monthlyint = 0;
        subtotal = savingsBalance * annualInterestRate;
        monthlyint = subtotal / 12;
        savingsBalance = monthlyint + savingsBalance;
        return savingsBalance;
    }
    
    void setInterestRate (float my_interest_rate)
    {
        annualInterestRate = my_interest_rate ;
    }
    void printSavingsBalance()
    {
        cout << "Your balance is: $" << savingsBalance << endl;
    }
};
#endif
#include <iostream> 
#include "SavingsAccount.h"
using namespace std;

int main()
{
    SavingsAccount saver1 (1, 2) ;        //instantiate saver1;
    SavingsAccount saver2 (2, 3) ;        //instantiate saver2;

    saver1.printSavingsBalance();
    cout << "Interest of Month #1" << saver1.calculateMonthlyInterest() << endl;
    saver1.setInterestRate (4);
    cout << "Interest of Month #2" << saver1.calculateMonthlyInterest() << endl;
    return 0;
}

Hope it helped, bye.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Yeah post your effort here and then maybe we would be able to help you out, just asking for code here would not fetch much help.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I think you are getting the formulas for deviation and variace wrong.

See this code for reference;

#include <iostream>
#include<iomanip>
#include <cmath>
using namespace std;

int main()
{
    float deviation, var ;
    char choice;
    int total_numbers  = 0 ;
    const int arraysize=20;
    int num[arraysize];
    do
    {
        cout<<"I will give you the Sum,Mean,Var & the Std Dev of any series of numbers?Y/N:"<<endl;
        cin>>choice;
        if(choice =='Y'||choice =='y')
        {
            cout<<"How many numbers will you enter? (up to 20)?";
            cin >> total_numbers ;  // this is correct way of accpeting single number
            for (int j=0; j < total_numbers; j++)
            {
                cout<<"Enter Number"<<j+1<<":"; cin>> num[j];
            }
            cout << " You have entered the following:"<<endl;
            for ( int j = 0;  j < total_numbers; j++)
            {
                cout << num[j]<<" ";
            }

            int sum=0;
            for (int j=0; j <  total_numbers; j++)
                sum+= num[j];
            cout<<"\nThe Sum is "<<sum<<endl;
            float mean= (sum/ total_numbers);
            cout << showpoint << fixed << setprecision (2);
            cout<<"The Mean is "<<mean<<endl;

            if (total_numbers > 1)
            {
                for (int i = 0; i < total_numbers; ++i )
                {
                    var += ((num [i] - mean) * (num [i] - mean)) ;
                }
                var /= (total_numbers - 1) ;
                deviation =sqrt(var);
            }

            else
            {
                var = 0.0 ;
                deviation = 0.0 ;
            }
            cout << showpoint << fixed << setprecision (2);
            cout<<"The Varience is " <<var<<endl;
            cout << showpoint << fixed << setprecision (2);
            cout<<"The Standard deviation is "<<deviation<<endl;
        }
    }
    while(choice!='N'&& choice!='n');
    return 0;

}

Maybe for the formula you should look here;

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
#include <iostream>
#include<iomanip>
#include <cmath>
usingnamespace std;
int main()
{

    char choice;
    int total_numbers = 0;
    const int arraysize = 20;
    int num[arraysize];
    do {

    cout << "I will give you the Sum,Mean,Var & the Std Dev of any series of numbers?Y/N:" << endl;
    cin >> choice;
    if (choice == 'Y' || choice == 'y') {

        cout << "How many numbers will you enter? (up to 20)?";
// cin>>num[arraysize];  this is wrong it means entering value in 20th element
        cin >> total_numbers;   // this is correct way of accpeting single number
        for (int j = 0; j < total_numbers; j++) {
        cout << "Enter Number" << j + 1 << ":";
        cin >> num[j];
        }

        cout << " You have entered the following:" << endl;
        for (j = 0; j < total_numbers; j++) {
        cout << num[j] << " ";
        }
        int sum = 0;
        for (j = 0; j < total_numbers; j++)
        sum += num[j];
        cout << "nThe Sum is " << sum << endl;
        float mean = (sum / total_numbers);
        cout << showpoint << fixed << setprecision(2);
        cout << "The Mean is " << mean << endl;
        float var = ((num[0] - mean) * pow(num[0] - mean, 2) + (num[1] - mean) * pow(num[1] - mean, 2) + +(num[2] - mean) * pow(num[2] - mean, 2)) / (num[arraysize - 1]);
        cout << showpoint << fixed << setprecision(2);
        cout << "The Varience is " << var << endl;
        float sqrtvar = sqrt(var);
        cout << showpoint << fixed << …
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Not sure whether it would work for TurboC and the old command.com shell, but you could try creating the command using double quotes to handle filenames with spaces. Don't know what will happen for long file names though.

e.g.

copy [B]"[/B]c:\yserver.txt[B]"[/B] [B]"[/B]c:\documents and settings\luffy-san\desktop\tcp1241_assignment3\lecture notes\server.txt[B]"[/B]

Yep it works. Dont know where you found out about this one but this sure is informative, hats off (and of course rep)to you.

Your friend,

~s.o.s~

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

There is nothing wrong with your program, it is the command which is incorrect. Do some research on the DOS Copy command to find out the valid commands and the format of the command. Look at the link which i had given in my 4th or 5th post on the previous page.

Hope it helped, bye.

@Mr. Salem : What is the difference if the compiler is 16 bit or 32 bit since the "copy" command which is executed in DOS mode runs in 16 bit. Try out the commands written by the guy in the DOS window without the program, jsut type it and still it doesnt work so i guess no mistake of teh compiler.
But then again maybe i am wrong somewhere, please let me know where it is?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I get the following error on the first line of my array...

" syntax error before `}' token "

My eyes are about to fall out of my skull. Can someone take a look for me, everything seems to be fine, but maybe I'm blind.


Here is the code in question...

int bin[26][5]={
                  {0,0,0,0,0},(0,0,0,0,1},{0,0,0,1,0},{0,0,0,1,1},{0,0,1,0,0},{0,0,1,0,1},
                  {0,0,1,1,0},{0,0,1,1,1},{0,1,0,0,0},{0,1,0,0,1},{0,1,0,1,0},{0,1,0,1,1},
                  {0,1,1,0,0},{0,1,1,0,1},{0,1,1,1,0},{0,1,1,1,1},{1,0,0,0,0},{1,0,0,0,1},
                  {1,0,0,1,0},{1,0,0,1,1},{1,0,1,0,0},{1,0,1,0,1},{1,0,1,1,0},{1,0,1,1,1},
                  {1,1,0,0,0},{1,1,0,0,1}
                  };

The thing marked in red in a round brace which should be replced by curly braces.

Hope it helped, bye.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Glad we could be of assistance and most of the credit of this problem solved goes to Mr. Salem for pointing out that it was actually the command string which was getting messed up, I just picked up his idea and completed it for you.

Best of luck.