Thread: First part of string runs but 2nd. wont

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    9

    First part of string runs but 2nd. wont

    Hi all i have an assignment to take enter 5 grades then average them, then enter 2 whole numbers and divide them to output one whole number with it's remainder.I'm stuck at the moment because it runs the 1st half of the program then the program ends never even starting the 2nd half of it here is what I have so far.

    Code:
    #include <iostream>
    #include <string>
    #include <int>
    using namespace std;
    int main()
    {
    
        
        
        
        
    
    //declaring variables
        
    string name;
    
    
    
    double grade_1,grade_2,grade_3,grade_4,grade_5;
    
    double avg;
    
    
    //get input from user
    cout << "Please enter your name:"  ";
    cin >> name;
    cout << endl;
    
    cout << "Enter first grade:"  ";
    cin >> grade_1 ;
    if(grade_1<0)
    grade_1=0;
    cout << endl;
    
        cout << "Enter second grade:"  ";
    cin >> grade_2 ;
    if(grade_2<0)
    grade_2=0;
    cout << endl;
    
    cout << "Enter third grade:"  ";
    cin >> grade_3 ;
    if(grade_3<0)
                grade_3=0;
    cout << endl;
    
    cout << "Enter forth grade:"  ";
    cin >> grade_4 ;
    if(grade_4<0)
                grade_4=0;
    cout << endl;
    
    cout << "Enter fifth grade:"  ";
    cin >> grade_5 ;
    if(grade_5<0)
                grade_5=0;
    cout << endl;
    
    
    
    // Finding the avrage
    avg = (grade_1+grade_2+grade_3+grade_4+grade_5) /5 ;
    cout << "Your average is: " << avg;
    
    
    int 1stNumber;
    
         double 2ndNumber;
    
    cout << "enter 2 whole numbers: " << endl; 
    cin >> 1stNumber >> 2ndNumber;
    cout <<1stNumber  << " divided by " << 2ndNumber
             << " is " << (1stNumber / 2ndNumber) << endl
             << "with a remainder of " << (1stNumber % 2ndNumber)
             cout << endl;
    return 0;
    }
    Any help or comments would be appreciated.
    Last edited by guyver074; 09-02-2012 at 07:10 AM. Reason: updated code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. It wont display my string
    By laxkrzy in forum C Programming
    Replies: 4
    Last Post: 11-16-2010, 11:40 AM
  2. Parse A Part of String
    By Ali.B in forum C Programming
    Replies: 8
    Last Post: 08-07-2009, 03:07 PM
  3. Printing part of a string
    By AngKar in forum C Programming
    Replies: 9
    Last Post: 04-24-2006, 04:49 AM
  4. Copying part of a string
    By Aluvas in forum C++ Programming
    Replies: 2
    Last Post: 11-20-2002, 10:33 PM
  5. string cluster part 2
    By ronin in forum C Programming
    Replies: 2
    Last Post: 12-18-2001, 07:04 PM