View Poll Results: Who trys to Comply with the most recent standards of C++ when programming?

Voters
4. You may not vote on this poll
  • I comply

    3 75.00%
  • Too much effort

    1 25.00%

Thread: Coding Error

  1. #1
    I'll take you down! polonyman's Avatar
    Join Date
    Sep 2004
    Posts
    50

    Post Coding Error

    Hey. Im struggling with my first real program. Its real basic but it will be funny. Can sum1 look at it and fix it?
    Code:
    #include <iostream.h>
    int fav(int x);
    int main()
    {
        int x;
        int random(101);
        x=random(101);
        {
            cout<<"Please hit Enter when you are ready to hear your fortune";
        }    
        if(x>1&&<11)
        {
            cout<<"You will be a loner for ever!";<<fav(x)
        }        
        else if(x>=11&&<21)
        {
            cout<<"You may meet a mole!";<<fav(x)
        }
        else if(x>=21&&<31)
        {
            cout<<"Dont expect much, but you may get lucky.";<<fav(x)
        }
        else if(x>=31&&<41)
        {
            cout<<"You will meet a good housewife, then get divorced, driving you broke!";<<fav(x)
        }
        else if(x>=41&&<51)
        {
            cout<<"You will meet a good slut";<<fav(x)
        }
        else if(x>=51&&<61)    
        {
            cout<<"You are likely to get laid a fair bit!";<<fav(x)
        }
        else if(x>=61&&<71)
        {
            cout<<"You will meet a hot person with nice rack, but she only married you for money!";<<fav(x)
        }
        else if(x>=71&&<81)
        {
            cout<<"You will be a porn star";<<fav(x)
        }
        else if(x>=81&&<91)
        {
            cout<<"Expect a good root all the time!";<<fav(x)
        }
        else if(x>=91&&<101)
        {
            cout<<"You will be a cuban I am sillyI am sillyI am sillyI am silly master!";<<fav(x)
        }
        else if(x<0)
        {
            cout<<"You will be a virgin and a prostitute wouldnt screw you if you paid her!";<<fav(x)
        }
    int fav(int x)
        {
        return x;
    }    
    }
    thankz

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Inside your if expressions is where your problem is.

    Code:
    else if(x>=81&&<91)
    is wrong. Change it to:
    Code:
    else if(x>=81 && x<91)

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Also remove the line that reads
    Code:
    int random(101);

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Another problem:

    You cant put a function inside another function like that. Move the fav() function outside:

    Code:
    int fav(int x);
    
    int main()
    {
       // main code here
    }
    
    int fav(int x)
    {
       return x;
    }

  5. #5
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Couple more things (sorry, for the multiple posts):

    You should probably change your include to :
    Code:
    #include <iostream>
    iostream is the standard library, where iostream.h is the depreciated library.

    Also your main() function should return something (just return 0 at the end). Most compilers will let you get away without returning something, but in reality it's best to have the program return a value.

  6. #6
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Well I see alot of errors I would recommed normally that you look at your compiler output but since your new also for future refenece don't ever expect someone here to "fix" your code we are just here to help you along not do the work for you but i remeber how it fells to be new.
    Code:
    #include <iostream>
    #include <cstdio>
    using std::cout;
    using std::cin;
    
    int main()
    {
        srand(time(NULL));//To give you random numbers based on the time
        int x = rand()%101 ;//random number between 1 and 100
        //int random(101); was not needed
        cout<<"Please hit Enter when you are ready to hear your fortune";
        cin.get();//so you actully have to hit enter
        //needed to add the x to the other side    
        if(x>1&&x<11)
        {
            cout<<"You will be a loner for ever!";//these arn't needed <<fav(x)
        }        
        else if(x>=11&&x<21)
        {
            cout<<"You may meet a mole!";
        }
        else if(x>=21&&x<31)
        {
            cout<<"Dont expect much, but you may get lucky.";
        }
        else if(x>=31&&x<41)
        {
            cout<<"You will meet a good housewife, then get divorced, driving you broke!";
        }
        else if(x>=41&&x<51)
        {
            cout<<"You will meet a good slut";
        }
        else if(x>=51&&x<61)    
        {
            cout<<"You are likely to get laid a fair bit!";
        }
        else if(x>=61&&x<71)
        {
            cout<<"You will meet a hot person with nice rack, but she only married you for money!";
        }
        else if(x>=71&&x<81)
        {
            cout<<"You will be a porn star";
        }
        else if(x>=81&&x<91)
        {
            cout<<"Expect a good root all the time!";
        }
        else if(x>=91&&x<101)
        {
            cout<<"You will be a cuban I am sillyI am sillyI am sillyI am silly master!";
        }
        else if(x<0)
        {
            cout<<"You will be a virgin and a prostitute wouldnt screw you if you paid her!";
        }
    /* This function has no use what so ever 
    int fav(int x)
        {
        return x;
    }*/
      cin.get();//waits for enter agian
      return 0;    
    }
    Welcome
    Woop?

  7. #7
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    resistance is futile.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  3. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM