a program

This is a discussion on a program within the C++ Programming forums, part of the General Programming Boards category; could someone tell me what the error i am making is and how to fix it and thank you #include ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    255

    a program

    could someone tell me what the error i am making is and how to fix it and thank you


    #include <iostream.h>
    #include <math.h>
    #include <string.h>
    const int ArSize = 20;
    int next(int age, int year);
    void another(int count);
    int main()
    {
    int age;
    int year;
    cout <<"How old are you?\n";
    cin>>age;
    cout<<"Want to know if i can tell you what year you were born?\n";
    char respond [ArSize];
    cin.get();
    cin>>respond;
    if (strcmp(respond,"y")==0 || strcmp(respond, "Y")==0 || strcmp(respond,"Yes") || strcmp(respond,"yes"))
    {
    year = 2001 - age;
    cout<<"you were born in "<<year<<". see arent i smarter than you think ;p\n";
    }
    cout<<"Lets demonstrate function calling now shall we since what we jus did was \n declare variables manipulate them and use them \n";
    next(age, year);
    return 0;
    }
    int next(int age,int year)
    {
    cout<<"see here we are in this function called next which is going to \n remeber your age from the last function\n" ;
    cout<<"see your age is "<<age<<" and you were born in " << year << " \n";
    cout <<"but lets ask some more ?'s and demonstrate more things shall we not that \n you have a choice in the matter\n";
    another(4);
    return 0;
    }
    void another(int count)
    {
    cout<<"Ill give you a value to be displayed counted forward and backwards\n";


    cout<<endl<<cout;
    if (count >0)
    another(count - 1);
    cout<<"maybe that plan didnt work i couldnt get it to work right \n but that demonstrates high error rates in programming so im gonig to leave it in\n";
    int now;
    cout<<"pick a number\n";
    cin.get();
    cin>>now;
    cout<<"now im going to use a do while statement and then explain it\n";
    do
    {
    cout<<"math is fun";
    cout<<"at this point i dont remeber your age and year of birth because i didnt \n carry it over\n";
    cout<<"im going to display this text over and over until ur number is up to 100000\n";
    }
    while (now < 100000);
    {
    for ( int i = now;i > 100000;i++)
    cout << i<<;
    cout<<endl;


    }
    cout<<"now wasnt that fun now there is one more control statement\n";
    int t;
    cout<<"pick the magic number \n";
    cin.get();
    cin>>t;
    switch (t)
    {
    case 8:
    cout<<"you got it good job\n";
    break;
    }
    cout<<"well this was fun but im going to end it now so good night since im writing this at night\n";

    }



    --------------------Configuration: skkoool - Win32 Debug--------------------
    Compiling...
    skkoool.cpp
    C:\skkoool.cpp(57) : error C2059: syntax error : ';'
    Error executing cl.exe.

    skkoool.obj - 1 error(s), 0 warning(s)

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    53

    Hm

    I think your problem may lie here :

    Code:
    // Ok... this makes sense 
    
    do 
    { 
    .....
    .....
    } 
    while (now < 100000); 
    
    {       // what's this brace related to?
    
    for ( int i = now;i > 100000;i++)  // perhaps a brace here needed?
    cout << i<<; 
    
    cout<<endl; 
    
    }       // and this one? what's it for...
    
    
    // try this syntax instead :
    
    for(....;....;....) {
    ...      // what you want to loop
    ...
    ...
    ...
    }
    
    do {
    ...     // what you want to loop
    ...
    ...
    } while(.......);
    The for-loop will try and loop the next line down if you don't use braces (and no others).

    Also I think your while-loop may not want to increment indefinitely (change the > sign to < perhaps?).

    You also seem to be calling another() from within another() which, whilst it's probably what you mean to do, you mustn't forget that it'll do all the code after it once it returns from the function call (if you see what I mean...).


    Almosthere
    "Technology has merely provided us with a more efficient means for going backwards" - Aldous Huxley

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    30
    Remove the second set of '<<' from the cout in line 57:-

    cout<<i;

    also, you may need to enclose the 8 in the case statement in single quotes:-

    case '8':

    This compiled to give no errors, but I didn't check if the program works as anticipated.
    Homer

    D'OH!

    mmmmmmmm... iterations

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21