How program can ask me to put value?

I have to code this program Write a user friendly C++ program to:
1) Declare, read in and print out your name as a string.
2) Calculate power from voltage and current values entered by the user. Note Power=voltage * current. Generate a tabular display (line up the inputs and answer under headings) of the input and output in decimal form.


Sample output:

Name

Voltage Current Power
(volts) (amps) (watts)
5 8 40

And here I come up with that;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Lab 3.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string name="";
	float voltage=0.0f;
	float current=0.0f;
	float power=0.0f;

	cout<<"Enter name:";
	cin>>name;
	cout<<"Your name:"<<name<<endl;
	cout<<"Enter voltage:";
	cin>>voltage;
	
	
	return 0;
}



How should I code so that program may ask me to put the value of voltage and current?

Thank you!
closed account (2UD8vCM9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string name="";
	float voltage=0.0f;
	float current=0.0f;
	float power=0.0f;

	cout<<"Enter name:";
	cin>>name;
	cout<<"Your name:"<<name<<endl;
	cout<<"Enter voltage:";
	cin>>voltage;
	cout << "Enter current:";
	cin>>current;
	power = voltage*current;
	
	
	return 0;
}


That would have your program get your voltage/current/power. For some reason, I have a feeling that isn't what you meant to ask for.
Last edited on
First of all, sting was not utilized right. Look here and look for the title "cin and strings": http://www.cplusplus.com/doc/tutorial/basic_io/

The question you asked, you already half answered. Also see that link for your answer.
Okay! I got it.
Thank you! :)
Last edited on
Topic archived. No new replies allowed.