Newbie in C++ and error with run program

This is a discussion on Newbie in C++ and error with run program within the C++ Programming forums, part of the General Programming Boards category; Hi all,,, I'm using Visual C++ 2008 and i made small program with console application to calculate student mark And ...

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    8

    Newbie in C++ and error with run program

    Hi all,,,

    I'm using Visual C++ 2008 and i made small program with console application to calculate student mark

    And the problem is "when I run the program this window coming"
    Error Image

    And I checked the path in the same folder for projects I saw it like this
    C:\Documents and Settings\Mohammad\My Documents\Visual Studio 2008\Projects\why\sss\sss\Debug\sss.exe

    How can I solve this problem?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You probably have to post your code.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Dec 2008
    Posts
    8
    Code:
    #include <iostream.h>
    using namespace std;
    
    int grade;		// Declaring Variable
    
    void main ()
    {
    cout << "Enter Student Mark >";	// To show "Enter Student Mark >" on screen
    cin >> grade;	// To Enter Student Mark
    
    // Testing Mark
    if (grade > 100 || grade < 0) {cout << "Wronge Value";}
    else
    	if (grade >= 90) {cout << "A";}
    	else
    		if (grade >= 80) {cout << "B";}
    		else
    			if (grade >= 70) {cout << "C";}
    			else
    				if (grade >= 60) {cout << "D";}
    				else
    					{cout << "F";}
    }
    I checked in the university it was working but in my home it is not working!

  4. #4
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    That's a very messy code o.o
    All those else, if, else, if, need cleaning ever heard of else if?
    Other than that I dunno about error :P
    Currently research OpenGL

  5. #5
    The larch
    Join Date
    May 2006
    Posts
    3,573
    There are a few things wrong.

    Code:
    #include <iostream.h>
    C++ standard headers don't have an extension, so it's <iostream>

    Code:
    void main ()
    The correct signature is
    Code:
    int main()
    Perhaps your home compiler didn't compile the code because of that and you indeed don't have the executable.

    Other notes: I don't think you need to keep indenting with else ifs, and the variable grade has no reason being a global (better declare in main).
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  6. #6
    Registered User
    Join Date
    Dec 2008
    Posts
    8
    Thank you very much

    I wrote it like this
    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
    int grade;
    cout << "Enter Student Mark >";	// To show "Enter Student Mark >" on screen
    cin >> grade;	// To Enter Student Mark
    
    // Testing Mark
    if (grade > 100 || grade < 0) {cout << "Wronge Value";}
    else
    	if (grade >= 90) {cout << "A";}
    	else
    		if (grade >= 80) {cout << "B";}
    		else
    			if (grade >= 70) {cout << "C";}
    			else
    				if (grade >= 60) {cout << "D";}
    				else
    					{cout << "F";}
    return 0;
    }
    now its running but when i write any mark it is exit the window to the c++ without grade

    what is the problem?

    This if and else for our lesson in the university

  7. #7
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Try adding " << endl ;" to the end of your cout instructions, as in

    cout << "F" << endl ;
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  8. #8
    Registered User
    Join Date
    Dec 2008
    Posts
    8
    Thank you Dino

    but same problem

    not showing the grade

  9. #9
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    Well, do you mean the window just shuts down, or is the grade not getting outputted onto the screen?
    Currently research OpenGL

  10. #10
    Registered User
    Join Date
    Dec 2008
    Posts
    8
    window started ok and i wrote the mark but grade not getting outputted onto the screen

  11. #11
    Registered User
    Join Date
    Nov 2008
    Posts
    41
    It's because once you enter the mark the program just runs through finishes, without giving you enough time to see the grade. Try adding this to the end of your program:

    Code:
    int nothing;
    cin >> nothing;

  12. #12
    Registered User
    Join Date
    Dec 2008
    Posts
    8
    Thank you Noise now it's ok

  13. #13
    Registered User
    Join Date
    Nov 2008
    Posts
    44
    well you should add something like
    Code:
    system("PAUSE");
    this adds at the end of your script a message that says: "Press any key to continue..." so when you press a key it exits...

  14. #14
    Registered User
    Join Date
    Nov 2008
    Posts
    41
    Yes I forgot about that one

  15. #15
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,546
    Quote Originally Posted by Cherry65 View Post
    well you should add something like
    Code:
    system("PAUSE");
    this adds at the end of your script a message that says: "Press any key to continue..." so when you press a key it exits...
    No, don't. Unportable and unnecessary.
    Instead, hit Ctrl+F5 or Run without Debug.
    The window will stay open after the application quits.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

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