11 Replies - 1423 Views - Last Post: 14 September 2013 - 08:01 AM Rate Topic: -----

#1 wynterxx   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 14-September 13

GPA Calculator Skipping Input

Posted 14 September 2013 - 04:28 AM

This is my first semester in C++ and I am very inexperienced. I am to make a GPA calculator that includes credit hours. I thought this would be really simple but I am having some issues. Here is what I have so far. I ran it just to see if it would work and it is skipping all but the first input. I also tried a system pause and it is still doing the same thing.

Any tips would be greatly appreciated. Thank you very much for your time. :)/>

 
// Include statements
#include <iostream>
using namespace std;

// Main function
int main ()
{
//Collect and assign variables for grades and credit hours.
 int grade1 =0;
 int grade2 =0;
 int grade3 =0;
 int grade4 =0;
 int grade5 =0;
 int hours1 =0;
 int hours2 =0;
 int hours3 =0;
 int hours4 =0;
 int hours5 =0;

   cout << "Welcome to Heather's GPA calculator. This will work for 5 grades." << endl;
   cout << "Please enter your first grade. A=4, B=3, C=2, D=1, F=0" << endl;
   cin >> grade1;
   cout << "How many credit hours is this course?" << endl;
   cin >> hours1; 
   cout << "Please enter your second grade. A=4, B=3, C=2, D=1, F=0" << endl;
   cin >> grade2;
   cout << "How many credit hours is this course?" << endl;
   cin >> hours2;
   cout << "Please enter your third grade.  A=4, B=3, C=2, D=1, F=0" << endl;
   cin >> grade3;
   cout << "How many credit hours is this course?" << endl;
   cin >> hours3;
   cout << "Please enter your fourth grade.  A=4, B=3, C=2, D=1, F=0" << endl;
   cin >> grade4;
   cout << "How many credit hours is this course?" << endl;
   cin >> hours4;
   cout << "Please enter your fifth grade.  A=4, B=3, C=2, D=1, F=0" << endl;
   cin >> grade5;
   cout << "How many credit hours is this course?" << endl;
   cin >> hours5;

return 0;
  
}




Is This A Good Question/Topic? 0
  • +

Replies To: GPA Calculator Skipping Input

#2 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3872
  • View blog
  • Posts: 14,211
  • Joined: 08-August 08

Re: GPA Calculator Skipping Input

Posted 14 September 2013 - 05:13 AM

cin is expecting all integers. Is that what you're entering?
Was This Post Helpful? 1
  • +
  • -

#3 wynterxx   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 14-September 13

Re: GPA Calculator Skipping Input

Posted 14 September 2013 - 06:58 AM

Yes, when I put 4 in it will actually just accept the number and not do anything else.
Was This Post Helpful? 0
  • +
  • -

#4 snoopy11   User is offline

  • Engineering ● Software
  • member icon

Reputation: 1594
  • View blog
  • Posts: 5,010
  • Joined: 20-March 10

Re: GPA Calculator Skipping Input

Posted 14 September 2013 - 07:05 AM

Hi,

When you find yourself writing basically the same block of code 5 times.

You should be thinking about 'loops' and 'arrays'.

also please read cin.ignore();

Regards

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3872
  • View blog
  • Posts: 14,211
  • Joined: 08-August 08

Re: GPA Calculator Skipping Input

Posted 14 September 2013 - 07:09 AM

When I put 4 in and hit enter it asks me:

Quote

How many credit hours is this course?


snoopy11, I doubt the OP has covered arrays yet.

... and doesn't cin.ignore() apply when using cin.get()?
Was This Post Helpful? 1
  • +
  • -

#6 snoopy11   User is offline

  • Engineering ● Software
  • member icon

Reputation: 1594
  • View blog
  • Posts: 5,010
  • Joined: 20-March 10

Re: GPA Calculator Skipping Input

Posted 14 September 2013 - 07:12 AM

Your right,

I really need some sleep.. been up all night..


night night.

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#7 wynterxx   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 14-September 13

Re: GPA Calculator Skipping Input

Posted 14 September 2013 - 07:16 AM

I probably should have mentioned this, but our professor hasn't covered loops and arrays yet and doesn't want us to use it in this assignment.

For some reason mine just is not asking me for the credit hours. I wonder why that is.
Was This Post Helpful? 0
  • +
  • -

#8 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3872
  • View blog
  • Posts: 14,211
  • Joined: 08-August 08

Re: GPA Calculator Skipping Input

Posted 14 September 2013 - 07:21 AM

What compiler are you using? I copied/pasted your code into a new project and made no changes when I tested it in Xcode.
Was This Post Helpful? 0
  • +
  • -

#9 wynterxx   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 14-September 13

Re: GPA Calculator Skipping Input

Posted 14 September 2013 - 07:32 AM

I am using Turing I believe.
Was This Post Helpful? 0
  • +
  • -

#10 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3872
  • View blog
  • Posts: 14,211
  • Joined: 08-August 08

Re: GPA Calculator Skipping Input

Posted 14 September 2013 - 07:42 AM

Do you mean Turbo? If so, you need to get a better (not obsolete) compiler.
Was This Post Helpful? 0
  • +
  • -

#11 jimblumberg   User is offline

  • member icon

Reputation: 5916
  • View blog
  • Posts: 17,932
  • Joined: 25-December 09

Re: GPA Calculator Skipping Input

Posted 14 September 2013 - 07:45 AM

As already stated by others, there appears to be nothing wrong with your program. Here is the output I received when I ran the program:

Quote

Welcome to Heather's GPA calculator. This will work for 5 grades.
Please enter your first grade. A=4, B=3, C=2, D=1, F=0
1
How many credit hours is this course?
1
Please enter your second grade. A=4, B=3, C=2, D=1, F=0
1
How many credit hours is this course?
1
Please enter your third grade. A=4, B=3, C=2, D=1, F=0
1
How many credit hours is this course?
1
Please enter your fourth grade. A=4, B=3, C=2, D=1, F=0
1
How many credit hours is this course?
1
Please enter your fifth grade. A=4, B=3, C=2, D=1, F=0
1
How many credit hours is this course?
1


Jim
Was This Post Helpful? 1
  • +
  • -

#12 wynterxx   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 14-September 13

Re: GPA Calculator Skipping Input

Posted 14 September 2013 - 08:01 AM

The one I am using is absolutely awful. Everyone in my class has been complaining, but it is the one he wants us to use. I plan on downloading a new one asap anyway.

Thanks for your help everyone. The fact that it is working on your end is enough for me.

I really appreciate your time.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1