Welcome to Dream.In.Code
Become a C++ Expert!

Join 150,240 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,337 people online right now. Registration is fast and FREE... Join Now!




statement needed

 
Reply to this topicStart new topic

statement needed

grimmben
2 Dec, 2007 - 02:40 PM
Post #1

New D.I.C Head
*

Joined: 25 Nov, 2007
Posts: 27


My Contributions
CODE
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
    //declare variables
    double score    = 0.0;
    double totalPoints = 0.0;  //accumulator
    char grade         = ' ';

    //get first score
    cout << "First score (negative number to stop): ";
    cin >> score;
  
    while (score >= 0)
    {
        //add score to accumulator
        totalPoints = totalPoints + score;
        //get next score
        cout << "Next score (negative number to stop): ";
        cin >> score;
    }   //end while

    //assign grade
    if (totalPoints >= 360)
        grade = 'A';
    else if (totalPoints >= 320)
        grade = 'B';
    else if (totalPoints >= 280)
        grade = 'C';
    else if (totalPoints >= 240)
        grade = 'D';
    else grade = 'F';
    //end ifs

    //display total points and grade
    cout << "totalPoints: " << totalPoints << endl;
    cout << "Grade: " << grade << endl;

    return 0;
}   //end of main function


In this program, when the user enters a score over one hundred
the program would ask is this score correct, what statement would
use to make this happen and where would I enter it in a program.

User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Statement Needed
2 Dec, 2007 - 03:44 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
You would put an if statement right after where they entered the value. So it would look like so...

CODE

cout << "First score (negative number to stop): ";
cin >> score;

char confirm = 'n';

if (score > 100) {
     cout << "Is this score correct? (y/n): ";
     cin >> confirm;
}

// more code here



You might also want to consider a loop so that you can loop around upon them confirming no, it would prompt them again for another number.

Hope this is what you were asking for.

Enjoy!

"At DIC we be score confirming code ninjas!" decap.gif

This post has been edited by Martyr2: 2 Dec, 2007 - 03:44 PM
User is offlineProfile CardPM
+Quote Post

grimmben
RE: Statement Needed
2 Dec, 2007 - 04:06 PM
Post #3

New D.I.C Head
*

Joined: 25 Nov, 2007
Posts: 27


My Contributions
THANKS A MILLION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

QUOTE(Martyr2 @ 2 Dec, 2007 - 04:44 PM) *

You would put an if statement right after where they entered the value. So it would look like so...

CODE

cout << "First score (negative number to stop): ";
cin >> score;

char confirm = 'n';

if (score > 100) {
     cout << "Is this score correct? (y/n): ";
     cin >> confirm;
}

// more code here



You might also want to consider a loop so that you can loop around upon them confirming no, it would prompt them again for another number.

Hope this is what you were asking for.

Enjoy!

"At DIC we be score confirming code ninjas!" decap.gif


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/9/09 06:25AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month