d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Need Help With C++ Hw > Willing To Pay Fg
12Next
Add Reply New Topic New Poll
Member
Posts: 17,865
Joined: Nov 8 2006
Gold: 44.00
Apr 9 2014 11:26pm
My brain is hurting and cant think anymore tonight. It deals with arrays & loops. It's the first c++ class at my college so it must be easy for a lot of people.

must be done within 1hour and maybe a few mins xD because of a due date.

It's only 2 problems, will pay 50 fg per question(depending on simplicity for me to understand)

PM me if interested.

Plz thank you

This post was edited by ZergBer on Apr 9 2014 11:31pm
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Apr 9 2014 11:45pm
If you have a question post it here. Can't be bothered to read PMs. Too many clicks. Ain't nobody got time for that.
Member
Posts: 17,865
Joined: Nov 8 2006
Gold: 44.00
Apr 9 2014 11:54pm
Who Should I Text?
Enter seed
Enter friend 0
Enter friend 1
Enter friend 2
Enter friend 3
Enter friend 4
You should text: Bill
These other friends didn't make the cut:
Jamal
Andy
Damion
Edward

randomly selects one of five names

thats Question 1

This post was edited by ZergBer on Apr 9 2014 11:54pm
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Apr 10 2014 12:08am
Code
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
int seed, r;
string friends[5];
cout << "Who Should I Text?" << endl;
cout << "Enter seed" <<endl;
cin >> seed;

srand(seed);
for(int i = 0; i < 5; i++)
{
cout << "Enter fried " << i << endl;
cin >> friends[i];
}

r = rand() % 5;

cout << "You should text: " << friends[r] << endl;
cout << "These other friends didn't make the cut:" << endl;
for(int i = 0; i < 5; i++)
{
if(i != r)
cout << friends[i] << endl;
}

return 0;
}


Happy?

This post was edited by Minkomonster on Apr 10 2014 12:09am
Member
Posts: 17,865
Joined: Nov 8 2006
Gold: 44.00
Apr 10 2014 12:15am
Quote (Minkomonster @ Apr 10 2014 06:08am)
Code
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    int seed, r;
    string friends[5];
    cout << "Who Should I Text?" << endl;
    cout << "Enter seed" <<endl;
    cin >> seed;

    srand(seed);
    for(int i = 0; i < 5; i++)
    {
        cout << "Enter fried " << i << endl;
        cin >> friends[i];
    }

    r = rand() % 5;

    cout << "You should text: " << friends[r] << endl;
    cout << "These other friends didn't make the cut:" << endl;
    for(int i = 0; i < 5; i++)
    {
        if(i != r)
            cout << friends[i] << endl;
    }
 
    return 0;
}


Happy?


Genius! got time for another??
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Apr 10 2014 12:16am
sure why not.

This post was edited by Minkomonster on Apr 10 2014 12:16am
Member
Posts: 17,865
Joined: Nov 8 2006
Gold: 44.00
Apr 10 2014 12:19am
Quote (Minkomonster @ Apr 10 2014 06:16am)
sure why not


huehue took me 2 hours to try to figure it out..I feel so dumb now :( hey but I understood it! lol

This is a test. (ALL answers on the bottom were A btw)
Enter your answer for question 1
Enter your answer for question 2
Enter your answer for question 3
Enter your answer for question 4
Enter your answer for question 5
Enter your answer for question 6
Enter your answer for question 7
Enter your answer for question 8
Enter your answer for question 9
Enter your answer for question 10
Enter your answer for question 11
Enter your answer for question 12
Enter your answer for question 13
Enter your answer for question 14
Enter your answer for question 15
Enter your answer for question 16
Enter your answer for question 17
Enter your answer for question 18
Enter your answer for question 19
Enter your answer for question 20
Answer 1 is incorrect.
Answer 2 is incorrect.
Answer 5 is incorrect.
Answer 7 is incorrect.
Answer 9 is incorrect.
Answer 10 is incorrect.
Answer 11 is incorrect.
Answer 12 is incorrect.
Answer 13 is incorrect.
Answer 15 is incorrect.
Answer 16 is incorrect.
Answer 17 is incorrect.
Answer 18 is incorrect.
Answer 19 is incorrect.
Results (minimum 10 correct to pass):
You got 6 correct.
You missed 14.
You've failed.

BDAACABACDBCDADCCBDA <-----This are supposed to be the correct answers

This post was edited by ZergBer on Apr 10 2014 12:37am
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Apr 10 2014 12:31am
Code
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
string expected = "BDAACABACDBCDADCCBDA";
string actual = "";
char c;
int pass = 10;
int result = 0;
for(int i = 1; i <= expected.length(); i++)
{
cout << "Enter your answer for question " << i << endl;
cin >> c;
actual += toupper(c);
}

for(int i = 0; i < expected.length(); i++)
{


if(expected[i] == actual[i])
{
result++;

}
else
{
cout << "Answer " << i+1 << " is incorrect." << endl;
}

}

cout << "Results (minimum " <<pass << " correct to pass):" << endl;
cout << "You got " << result << " correct." << endl;
cout << "You missed " << expected.length() - result << "." << endl;
if(result >= pass)
cout << "You've passed." << endl;
else
cout << "You've failed." << endl;

return 0;
}


And I was being shitty for no reason before, which is why I edited my statement. But you went ahead and quoted me and kept it there for the record. Oh well.

This post was edited by Minkomonster on Apr 10 2014 12:34am
Member
Posts: 17,865
Joined: Nov 8 2006
Gold: 44.00
Apr 10 2014 12:41am
. :bouncy:

This post was edited by ZergBer on Apr 10 2014 12:55am
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Apr 10 2014 12:43am
Quote (ZergBer @ Apr 10 2014 01:41am)
what is toupper??

and can you help me out with this??

everything else worked except this one xD which I didnt mention

Driver's License Exam Grader
Enter your answer for question 1
Invalid input.  Enter only: A, B, C, or D.  Try again.
Enter your answer for question 1
Invalid input.  Enter only: A, B, C, or D.  Try again.
Enter your answer for question 1
Enter your answer for question 2
Enter your answer for question 3
Enter your answer for question 4
Enter your answer for question 5
Enter your answer for question 6
Enter your answer for question 7
Enter your answer for question 8
Invalid input.  Enter only: A, B, C, or D.  Try again.
Enter your answer for question 8
Enter your answer for question 9
Enter your answer for question 10
Enter your answer for question 11
Enter your answer for question 12
Enter your answer for question 13
Enter your answer for question 14
Invalid input.  Enter only: A, B, C, or D.  Try again.
Enter your answer for question 14
Enter your answer for question 15
Enter your answer for question 16
Enter your answer for question 17
Enter your answer for question 18
Invalid input.  Enter only: A, B, C, or D.  Try again.
Enter your answer for question 18
Invalid input.  Enter only: A, B, C, or D.  Try again.
Enter your answer for question 18
Invalid input.  Enter only: A, B, C, or D.  Try again.
Enter your answer for question 18
Enter your answer for question 19
Enter your answer for question 20
Answer 1 is incorrect.
Answer 12 is incorrect.
Answer 16 is incorrect.
Answer 17 is incorrect.
Answer 18 is incorrect.
Answer 19 is incorrect.
Answer 20 is incorrect.
Results (minimum 15 correct to pass):
You got 13 correct.
You missed 7.
You've failed.


toupper() takes a character and makes it uppercase. I did it didn't matter if you entered upper or lowercase. Looks like its supposed to be doing input validation to ensure you only enter uppercase


Code
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
string expected = "BDAACABACDBCDADCCBDA";
string actual = "";
char c;
int pass = 15;
int result = 0;
bool valid;

cout << "Driver's License Exam Grader" << endl;
for(int i = 1; i <= expected.length(); i++)
{

do
{
cout << "Enter your answer for question " << i << endl;
cin >> c;
valid = c == 'A' || c == 'B' || c == 'C' || c == 'D';

if(!valid)
{
cout << "Invalid input. Enter only: A, B, C, or D. Try again." << endl;
}
else
actual += c;

}while(!valid);


}

for(int i = 0; i < expected.length(); i++)
{


if(expected[i] == actual[i])
{
result++;

}
else
{
cout << "Answer " << i+1 << " is incorrect." << endl;
}

}

cout << "Results (minimum " <<pass << " correct to pass):" << endl;
cout << "You got " << result << " correct." << endl;
cout << "You missed " << expected.length() - result << "." << endl;
if(result >= pass)
cout << "You've passed." << endl;
else
cout << "You've failed." << endl;

return 0;
}


This post was edited by Minkomonster on Apr 10 2014 12:49am
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll