Noob C++ user, output problem

I am trying to make a gpa calculator for a class and I am having trouble figuring out how to convert the character values for the user to input into floats.

#include<iostream>
using namespace std;

int main()
{
float A = 4.0;

string G162;
floatG1621 = 0;
cout << "Grade?";
cin >> G162;
cin.ignore();
if(G162 == "A")
{
G1621 = 4.0;
}
cout << G1621 // this is an abbreviated version of the code, but for some reeason it isn't showing the 4


Why not do cin >> floatG1621?

Anyways if you didn't have that option then you can use one of our awesome standard library functions.
From <string> you can use std::stof http://www.cplusplus.com/reference/string/stof/
this is an abbreviated version of the code

It is indeed. However, if you add the small amount of punctuation to make it compile then it will actually return 4 in response to an input of "A".

So maybe you need to give sufficient code for it (a) to compile; (b) produce the error that you cite.

And please use [code] [/ code] tags (first item on the formatting menu).
Last edited on
Topic archived. No new replies allowed.