CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: C++ Math

  1. #1
    Join Date
    Mar 2013
    Posts
    4

    C++ Math

    I made a program that asks 18 questions in a do-while loop and then outputs either "correct" or "wrong" for each question. Is it possible to add a formula that will grade the questions that are answered correctly, like how a regular school test is averaged?

    How can I add this to my program? Here's my program:

    #include <iostream>
    #include <string>
    using namespace std;

    string answer;
    char repeat;

    int main()
    {
    do {
    cout<<"Come si dice domani?\n";
    cin>>answer;
    if (answer=="tomorrow" || answer=="Tomorrow")
    cout<<"Correct\n";
    else
    if(answer!="tomorrow"||"Tomorrow")
    cout<<"Sorry"<<endl;
    cout<<"Come si dice aqua?\n";
    cin>>answer;
    if (answer=="water" || answer=="Water")
    cout<<"Correct\n";
    else if(answer!="water"||"Water")
    cout<<"Sorry"<<endl;
    cout<<"Come si dice cibo?\n";
    cin>>answer;
    if (answer=="food" || answer=="Food")
    cout<<"Correct\n";
    else if(answer!="food"||"Food")
    cout<<"Sorry"<<endl;
    cout<<"Vuoi giocare di nuovo?";
    cin>>repeat;
    } while(repeat=='Yes'|| repeat=='yes'||repeat=='si'||repeat=='Si'||repeat=='Y');

    return 0;
    }
    Last edited by gamesun; August 5th, 2013 at 05:42 PM.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: C++ Math

    Yes

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: C++ Math

    Quote Originally Posted by gamesun View Post
    How can I add this to my program?
    And how would you do that with a sheet of paper? Forget about programming for some time and explain the algorithm step by step, in plain English.
    Best regards,
    Igor

  4. #4
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: C++ Math

    Quote Originally Posted by jimm1988 View Post
    you should take two values x,y and s for the sum where s=x+y and then its out put will be scanf("sum=%d,s) so lets try and i think you will be get it's answer.
    ?????????
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: C++ Math

    Quote Originally Posted by gamesun View Post
    I made a program that asks 18 questions in a do-while loop and then outputs either "correct" or "wrong" for each question.
    Explain what this is supposed to do:
    Code:
    if(answer!="tomorrow"||"Tomorrow")
    Whatever it is, it doesn't do what you think it does.

    Regards,

    Paul McKenzie

  6. #6
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: C++ Math

    Please use code tags when posting code and format the code properly before posting. Go Advanced, select code and click '#'.

    Code:
    while(repeat=='Yes'|| repeat=='yes'||repeat=='si'||repeat=='Si'||repeat=='Y');
    repeat is defined as a char so can only hold one character - so to test against a 'string' is incorrect.

    Also, strings are enclosed within " so 'Yes' is not correct - it should be "Yes"

    Code:
    if (answer == "tomorrow" || answer == "Tomorrow")
           cout << "Correct\n";
    else
        if (answer != "tomorrow" || "Tomorrow")
            cout << "Sorry" << endl;
    Apart from Paul's comment re the incorrect condition, you don't need the second if test because if the result of the first if statement is false, then the answer is incorrect so no further tests are needed.

    Code:
    if (answer == "tomorrow" || answer == "Tomorrow")
         cout << "Correct\n";
    else
        cout << "Sorry" << endl;
    Last edited by 2kaud; August 6th, 2013 at 03:45 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  7. #7
    Join Date
    Aug 2013
    Posts
    8

    Re: C++ Math

    @gamesun

    I think you could study this article: http://www.antedes.com/blog/csharp/p...htein-distance

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured