-
August 4th, 2013, 08:09 PM
#1
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.
-
August 4th, 2013, 08:21 PM
#2
-
August 5th, 2013, 01:15 AM
#3
Re: C++ Math
Originally Posted by gamesun
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
-
August 5th, 2013, 06:44 AM
#4
Re: C++ Math
Originally Posted by jimm1988
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)
-
August 5th, 2013, 07:50 PM
#5
Re: C++ Math
Originally Posted by gamesun
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
-
August 6th, 2013, 03:38 AM
#6
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)
-
August 7th, 2013, 12:46 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|