This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Nested If statements, int and strings

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My new assignment is to write a program to get a users name, have them input ten grade (int, number format), then convert those to letter grade format, and return all numeric and letter grades back to the user with an average as well. I wrote a test program to see if the first int and string would work before writing the entire code, but this is my first does of nested if statements, and I know there has to be a more efficient way to do this other than how I've built it. Can anyone tell me what I did wrong here and what the best practice is for such a program?

<code>#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;


int main (){

int grade1, grade2, grade3, grade4, grade5, grade6, grade7, grade8, grade9, grade10;
string username, letter1, letter2, letter3, letter4, letter5, letter6, letter7, letter8, letter9, letter10;

cout << "What is your user name? " << endl;
cin >> username;

cout << "What are the ten grades you received this semester?" << endl;
cin >> grade1;
cin >> grade2;
cin >> grade3;
cin >> grade4;
cin >> grade5;
cin >> grade6;
cin >> grade7;
cin >> grade8;
cin >> grade9;
cin >> grade10;


if ( 69 < grade1 <= 79)
letter1 = C;
if ( 79 < grade1 <= 89)
letter1 = B;
if ( 89 < grade1)
letter1 = A;



cout << " Grade = " << grade1 << " = " << letter 1 << endl;

return 0;
}

</code>
 
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jack,

Have you leant about arrays?
 
Jack Jutzi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, my class hasn't covered arrays yet, but I can look it up if that's the best approach to this.
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well some advice is that learning is advancing oneself, so even though your class hasn't thought the subject of arrays yet do go ahead and look it up as its a better solution for your problem...
While you're at it look up loops as well then try to figure out how to use the both concepts to solve your problem...
If you have any issues you can always come back for help...
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic