String Planet Program *URGENT*

I'm to write a program that outputs a user's weight on a planet they enter. The user must first input his/or her weight, then the planet this wish to see their weight on, then finally enter his/ or her name. The program must also output a statement that corresponds with the weight on the user. I've already created the statements in the code in a string array.

Here is what I have so far:

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main()
string planetName[8] = {"Mercury" , "Venus" , "Earth" , "Mars" , "Jupiter" , "Saturn" ,"Uranus" , "Neptune"};
string phrase[8] = {"You way the same!" , "You've been eating too much!" , "Eating too many hamburgers I see!" , "You must be exercising alot!" , "You need to eat more!" , "Woah you're thin!" , "You need to start dieting" , "You're eating way too much!"};
string name = "";
int weight = 0;
int weightOnPlanet[8] = {1, 2, 3, 4, 5, 6, 7, 8};

cout << "Please enter you're weight: ";
cin >> weight;

cout << "Enter the name of the planet you would like to see your weight on: ";
getline(cin , planetName);//here it tells me the getline function does not match the argument list

cout << "Enter your name: ";
getline(cin, name);

return 0;
} //end of main function
Last edited on
Why do you even need their name and weight if you just give a statement based on which planet they're on?
My teacher assigned it this way. :/

So, in your first post, you gave a description of your assignment, and you gave your current progress, but you haven't asked for help. What would you like help with? ;)
Last edited on
Oh, sorry :/

How would I go about solving this? I know I would need two for loops to search the arrays, but I just don't know where to necessarily start. And in the first getline statement, it says it does not match the argument list.

*I'm very new to coding*
Wow, I just realized I forgot to add the calculations array.
getline(cin , planetName);

planetName is your array of planet names, I'm sure you don't want the user to overwrite that. You need a separate variable to hold what the user said their planet is.

As for searching the planets, you only need one for-loop. You would go through each index in your planetName array and see if it matches what the user input, and when you reach the matching on you output the corresponding statement from your phrase array (just re-use the index).
You're entering the weight, which is an integer. The "\n" remains in the buffer. When you use getline to enter the planet, the newline character is the only thing that goes into the planetName (which should be a different name - like planetChoice) variable. You need to use the ignore function.
Topic archived. No new replies allowed.